3

I have a batch file called "ClockTalk.bat" that has 3 arguments:

nircmd.exe speak text "Attention it's now %1 %2, %3 Hours remain to the end of the day" -3

i use a vbscript called "HideBat.vbs" only to run the batch file with hidden dos screen:

'HideBat.vbs
CreateObject("Wscript.Shell").Run "ClockTalk.bat" & WScript.Arguments(0) & WScript.Arguments(1) & WScript.Arguments(2), 0, False

and i run it from the command line like this:

HideBat.vbs 12 10 am

and it always give me an error: System cannot find the file specified

or if i run it like this:

HideBat.vbs "12 10 am"

it always give me an error: Subscript out of range

So what is wrong in my files, and how to run the batch file from the vbscript and pass the three arguments to it from the command line ?

1

You forgot to account for spaces between arguments. So it's trying to run HideBat.vbs1210am, which isn't a legitimate file, so you get the "System cannot find the file specified" error.

When you run it as HideBat.vbs "12 10 am" you're making it so that you provided the 12 10 am as a single argument. So when the VBS script references the 2nd and 3rd arguments in the array, they don't exist, and so you get the "Subscript out of range" error.

Try something like:

CreateObject("Wscript.Shell").Run "ClockTalk.bat " & WScript.Arguments(0) & " " & WScript.Arguments(1) & " " & WScript.Arguments(2), 0, False

...to insert the spaces after the command and between the arguments.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.