473,503 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you launch a vbscript within vb.net?

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?

May 2 '06 #1
4 16063
swingheim
3 New Member
Try something like this:

Expand|Select|Wrap|Line Numbers
  1.     Dim p As System.Diagnostics.Process
  2.  
  3.     p.StartInfo.FileName = "C:\myfile.vbs"
  4.     p.StartInfo.Arguments = """C:\path with spaces to my arguments\myfile.txt"""
  5.     p.StartInfo.UseShellExecute = True
  6.  
  7.     p.Start(p.StartInfo)
  8.  
Now, the UseShellExecute may or may not be needed. Note that with the StartInfo, you can assign a lot of other options to the process.
May 2 '06 #2

"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in message
news:%2****************@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
May 2 '06 #3

"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in message
news:%2****************@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

May 2 '06 #4
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
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in
message news:%2****************@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

May 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3462
by: Trevor Fairchild | last post by:
I'm trying to have VB6 write an html file during run-time, with some VBScript functionality. The intent is to display images based on the current record within the program - using a WebBrowser -...
20
5943
by: Harag | last post by:
Hi All. I'm stating out doing some web developing. I was wondering which of the server side languages should I concentrate on and learn. I Know CSS, HTML, T-SQL I can look at the client...
17
3815
by: SK | last post by:
I am calling an exe thru' href, but when it executes, I get the message if I want to open the file(exe file). Is there any way I can suppress this from appearing and open the program? Thank...
16
9312
by: Mike Schinkel | last post by:
Does anyone know if there are bugs in VBScript's GetRef()? I'm using VBScript Version 5.6.8515 on Win2003Server w/ASP. Sometimes it returns an object that VarType() says is a vbObject. Other...
3
6763
by: David Shorthouse | last post by:
Hey folks, Not an off-topic posting.....since I was shot-down in an earlier post...this one's legit. How do I go about calling a server-side vbscript within a client-side javascript function?...
1
1728
by: pmclinn | last post by:
The code below is generated by an application that allows you to put a Microsoft assistant on a webpage. I'm having a heck of a time trying to get this script to launch on a server side button...
5
9647
by: Frank | last post by:
The following code will not work in my shtml page at all and I can not figure out the reason. I get the error that there is a "Type Mismatch 'Launch'" when i click the button. If i change the...
7
6157
by: dinamointer | last post by:
Could you help me in this problem: I want to launch an exe file(executable jar file) from a web page. I use jsp...and i cannot use vbScript...? could u tell me how should i do it? Thanks
1
1637
BezerkRogue
by: BezerkRogue | last post by:
I have created a VB Script to synchronize software versions and then launch an application on the system it is run against. The script runs and generates no errors but will not launch the second...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.