Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button_Click to run VB script

Status
Not open for further replies.
Apr 10, 2003
49
US
I have a button on my form and want it to run a VBScript whenever it is clicked. I've tried to call it as a file to open it, I've tried using shell. Any suggestions?
 
You should be able to run the script using ShellExecute. See the help on System.Management.Diagnostics namespace for more information.

Altenatively see if you can reference the old VB6 'Microsoft Script Control 1.0' COM component that allows you to run VBScript and JScript.

Bob Boffin
 
I tried to find system.management.diagnostics, and ShellExecute but I couldn't find it.

 
Sorry I wasn't thinking straight. In VB.NET you should be able to run the script using the Shell function.

Try something like:
Code:
Shell("cscript.exe " & MyVBScriptFileName)

cscript is a command line program that will run vbs, js or wsf files. There is an alternative windows version called wscript if you prefer it.

You may need to include the full path to cscript.exe (or wscript.exe) which is normally C:\Windows\System32




Bob Boffin
 
Here is my synatax
Dim test As String
test = "c:\test.vbs"
Shell("C:\WINNT\system32\cscript.exe" & test)

and here is my error message.

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in microsoft.visualbasic.dll

Additional information: File not found.

I double checked the path for the script and cscript.exe and the path is correct.

Thanks for your help.
 
I figured it out
Dim test As String
test = "c:\test.vbs"
Shell("C:\WINNT\system32\cscript.exe c:\test.vbs")
Thanks for all of your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top