Robie Nayak
Robie Nayak

Reputation: 827

pass parameters to batch file from vb script

I just want to execute a batch file stealthly from vb script. My vb script contains the following lines; but it doesn't work. Any idea what I am missing?

Dim min
Dim WshShell
min = InputBox("Enter the number of mins :")
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Users\XYZ\Desktop\test.bat " & min & Chr(34), 0 
Set WshShell = Nothing

Upvotes: 0

Views: 2119

Answers (2)

Robie Nayak
Robie Nayak

Reputation: 827

I did the following modifications to my code and it is working now.

Dim min
Dim WshShell
min = InputBox("Enter the number of mins :")
Set WshShell = CreateObject("WScript.Shell")
strCommand = "C:\Users\Rabindra\Desktop\test.bat " & min
WshShell.Run strCommand, 0, True
Set WshShell = Nothing

Upvotes: 0

Laoujin
Laoujin

Reputation: 10229

Try this:

Dim min
Dim WshShell
min = InputBox("Enter the number of mins :")
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """C:\temp\test.bat""" & min
Set WshShell = Nothing

Your problem was that the min parameter should be after the Chr(34).

WshShell.Run chr(34) & "C:\Users\XYZ\Desktop\test.bat " & Chr(34) & min, 0

Upvotes: 2

Related Questions