|
-
Mar 9th, 2006, 09:47 PM
#1
Thread Starter
New Member
VBScript within VB.NET question
I am a noobie at VB.NET, but I am trying to figure something out.
I have a few VBScript files I wrote and I know some VB.NET. I am trying to include these VBScript files within my compiled program and have it display the strings.
Basically, I want the VBScript files to run and then display them on a VB.NET form.
I am using Visual Basic .NET.
Thanks!
-
Mar 9th, 2006, 10:43 PM
#2
Addicted Member
Re: VBScript within VB.NET question
I'm a little confused by your post.
Are you wanting to just display the vbScript code as text somewhere in your program? Or are you wanting the vbScript to execute while on your form??
As far as I know, vbScript only runs through a web browser. You could use a webBrowser control on your form and run the vbScript through it but I don't think you can just run vbScript right off a form? ( like response.write("whatever...") wouldn't work on your form.)
-
Mar 9th, 2006, 10:46 PM
#3
Thread Starter
New Member
Re: VBScript within VB.NET question
VBScript
---
Code:
sProgramImageName1 = "firefox.exe"
Set oShell = CreateObject("WScript.Shell")
sComputer = "." ' use "." for local computer
Set oWmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& sComputer & "\root\cimv2")
sWmiQuery = "select Name from Win32_Process where name='" _
& sProgramImageName1 & "'"
Set oQResult = oWmi.ExecQuery(sWmiQuery)
If oQResult.Count = 0 Then
RunningProgram = sProgramImageName1
Else
RunningProgram = "test"
End If
VB.NET
---
Code:
Module Computer
Overloads Sub Main(ByVal args() As String)
Dim txtFile As System.IO.StreamWriter
Dim RunningProgram As String
Try
txtFile = New System.IO.StreamWriter("C:\code\test.txt")
txtFile.WriteLine(RunningProgram)
txtFile.Close()
Catch ex As Exception
Console.WriteLine("An error occured:" & vbCrLf & "Error text: " & ex.Message & vbCrLf & "Stack trace: " & ex.StackTrace & vbCrLf)
End
End Try
End Sub
End Module
When I run it, I see the txt file - but nothing written inside.
I'm guessing I need to use Microsoft.VisualBasic, but just not quite sure how to! Thanks!
Last edited by coolant; Mar 9th, 2006 at 11:05 PM.
-
Mar 9th, 2006, 11:31 PM
#4
Addicted Member
Re: VBScript within VB.NET question
You have ...
Dim RunningProgram As String
Try
txtFile = New System.IO.StreamWriter("C:\code\test.txt")
txtFile.WriteLine(RunningProgram)
Where do you set RunningProgram to anything?
You never set the string to = anything in vb.net.
Also, where do you have the vbScript code in your application? How is it getting into it? At first I thought you were reading it in as a text file. But I can't tell from the code.
Are you trying to use the RunningProgram variable from the vbScript to set the RunningProgram variable from VB module?? Are you passing the vbScript RunningProgram variable to the console application when you launch it?
Are you trying to write the entire vbScript code to the text file or just the RunningProgram variable from the vbScript code? (again. I can't tell)
If you want to use the RunningProgram vbScript variable and set the RunningProgram variable in vb.net to equal it, then I think the way you've coded this, you're creating what amounts to be a local RunningProgram Variable when you dimension it again as a string in .Net. So you can't use the RunningProgram variable from vbScript because RunningProgram is now a vb.net string variable that isn't equal to anything. - which is why nothing is wrote to the file also.
I don't know that I understand exactly what you're trying to do to be of much help.
-
Mar 9th, 2006, 11:38 PM
#5
Thread Starter
New Member
Re: VBScript within VB.NET question
Take a look at
http://www.derdy.com/vbnet.jpg
Like I said, I can build it - but I want to be able to use the Variable in the .NET code that I got from the VBScript code.
Is this possible?
-
Mar 9th, 2006, 11:56 PM
#6
Addicted Member
Re: VBScript within VB.NET question
Okay.
I'm not sure if it is possible. But if it is, you'd have to make RunningProgram a global variable. The way you've coded this, it is a local variable in sub main and you can't use the variable from the vbScript.
A class is global. So, maybe the vbScript is too? Try leaving out the name of your RunningProgram variable in the VB.NET. If the vbScript file is global, the variable would still be available. So no need to DIM RunningProgram again.
See if you get an error stating that RunningProgram is undefined when you use it in your WriteLine statement.
VB Code:
txtFile.WriteLine(RunningProgram)
If you get an error (it will not compile and run in debug) then the .Net isn't seeing the variable.
Start there...
-
Mar 9th, 2006, 11:59 PM
#7
Addicted Member
Re: VBScript within VB.NET question
I don't think that's going to work...
You've got me curious. I'm going to play with it some...
-
Mar 10th, 2006, 12:04 AM
#8
Thread Starter
New Member
Re: VBScript within VB.NET question
 Originally Posted by darth vador
If you get an error (it will not compile and run in debug) then the .Net isn't seeing the variable.
Start there...
.NET is not seeing the variable at all. If you could find a way to do this - I would love you forever!
I know what some of you may be thinking, "oh, just switch to VB.NET." Well, when you have thousands of lines of VBScript - it makes it most difficult. I'm trying to learn!
-
Mar 10th, 2006, 12:44 AM
#9
-
Mar 10th, 2006, 12:48 AM
#10
Thread Starter
New Member
Re: VBScript within VB.NET question
I created a desktop app using forms. No ASP here - only PHP 
Currently, I use a timer script..
Code:
If Timer2.Interval = 240000 Then
Dim oShell, a
oShell = CreateObject("Wscript.Shell")
a = "c:\code\test.vbs"
oShell.run(a, 3, True)
End If
but, it would be nice to be able to just compile all the vbs files into the .NET application and call them from there. Also, less of a chance to have people steal my code
-
Mar 10th, 2006, 08:22 AM
#11
Thread Starter
New Member
Re: VBScript within VB.NET question
Also, I found http://www.adminscripteditor.com/editor/scriptpackager/ which is an awesome program, but it costs $100.
Anybody know of another solution? Thanks!
-
Mar 15th, 2006, 07:17 PM
#12
Thread Starter
New Member
Re: VBScript within VB.NET question
-
Sep 20th, 2006, 09:41 AM
#13
Lively Member
Re: VBScript within VB.NET question
If I uderstand what you are trying to do correctly I did something similar to get the free disk space on servers.
the method I used was quick, dirty and not good practice (a bit ashamed of it) but it did work.
I used vb to make a text / .wsf file and shelled out to dos to run the script.
when the shell exited I read the output file of the script and pick out what i wanted.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|