Home All Groups Group Topic Archive Search About

How do you launch a vbscript within vb.net?

Author
2 May 2006 3:55 PM
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?

Author
2 May 2006 4:21 PM
Mythran
Show quote Hide quote
"Patrick Dugan" <patrick.dugan@usnetNOSMORESPAMcomcorp.com> wrote in message
news:%23inFpDgbGHA.3900@TK2MSFTNGP05.phx.gbl...
>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
Author
2 May 2006 4:23 PM
Mythran
Show quote Hide quote
"Patrick Dugan" <patrick.dugan@usnetNOSMORESPAMcomcorp.com> wrote in message
news:%23inFpDgbGHA.3900@TK2MSFTNGP05.phx.gbl...
>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
Author
2 May 2006 4:32 PM
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


Show quoteHide quote
"Mythran" <kip_potter@hotmail.comREMOVETRAIL> wrote in message
news:%23$xcwSgbGHA.4112@TK2MSFTNGP03.phx.gbl...
>
> "Patrick Dugan" <patrick.dugan@usnetNOSMORESPAMcomcorp.com> wrote in
> message news:%23inFpDgbGHA.3900@TK2MSFTNGP05.phx.gbl...
>>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
>
>