How do you launch a vbscript within vb.net?

P

Patrick Dugan

I am trying to launch a vbscript from within vb.net (vs2005)
The script itself requires a parameter of a filename to process.

I have tried:

Dim P As Process = Process.Start("C:\Temp\MyTest.vbs",
"MyFileToProcess.txt")

also

Dim P As Process = Process.Start("C:\winnt\system32\cscript.exe",
"C:\Temp\MyTest.vbs MyFileToProcess.txt")

also

Dim P As Process = Process.Start("C:\winnt\system32\wscript.exe",
"C:\Temp\MyTest.vbs MyFileToProcess.txt")


In all cases the process starts but the script never runs. The files are in
the correct location. Is there some better way in VS2005 to start a
vbscript and pass it a parameter?
 
M

Mythran

Patrick Dugan said:
I am trying to launch a vbscript from within vb.net (vs2005)
The script itself requires a parameter of a filename to process.

I have tried:

Dim P As Process = Process.Start("C:\Temp\MyTest.vbs",
"MyFileToProcess.txt")

also

Dim P As Process = Process.Start("C:\winnt\system32\cscript.exe",
"C:\Temp\MyTest.vbs MyFileToProcess.txt")

also

Dim P As Process = Process.Start("C:\winnt\system32\wscript.exe",
"C:\Temp\MyTest.vbs MyFileToProcess.txt")


In all cases the process starts but the script never runs. The files are
in the correct location. Is there some better way in VS2005 to start a
vbscript and pass it a parameter?

Using the last Process.Start, without only a path modification to point to
Windows\System32 since I'm running win2k, it runs fine for me. I created a
vbs called MyTest.vbs and ran it. I placed the following code in
MyTest.vbs:

Option Explicit

Dim args
Dim arg

Set args = WScript.Arguments

For Each arg In args
WScript.Echo arg
Next

The following is my Main method:

Public Shared Sub Main()
Dim p As Process = Process.Start("C:\windows\system32\wscript.exe",
"C:\Temp\MyTest.vbs MyFileToProcess.txt")
End Sub


HTH,
Mythran
 
M

Mythran

Patrick Dugan said:
I am trying to launch a vbscript from within vb.net (vs2005)
The script itself requires a parameter of a filename to process.

I have tried:

Dim P As Process = Process.Start("C:\Temp\MyTest.vbs",
"MyFileToProcess.txt")

also

Dim P As Process = Process.Start("C:\winnt\system32\cscript.exe",
"C:\Temp\MyTest.vbs MyFileToProcess.txt")

also

Dim P As Process = Process.Start("C:\winnt\system32\wscript.exe",
"C:\Temp\MyTest.vbs MyFileToProcess.txt")


In all cases the process starts but the script never runs. The files are
in the correct location. Is there some better way in VS2005 to start a
vbscript and pass it a parameter?

Oh, another thing ...

Does the path to the script have spaces in it? If it does, you will need to
wrap the path in double-quotes:

Dim p As Process = Process.Start( _
"C:\winnt\system32\wscript.exe",
"""C:\Temp\MyTest.vbs"" MyFileToProcess.txt" _
)

HTH,
Mythran
 
P

Patrick Dugan

Thanks! Yes the path does have spaces in the both the location of the
vbscript and the location of the file the script uses.
I'll try the double quote method. Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top