I am working on a batch script for my specific purpose.
The batch has launches a program like so:
start /w program.exe %1
This way I can easily pass variable to my batch using a shortcut. Like:
C:\mybatch.bat "My variable"
Because I the batch waits for the program to do its job, it could be open for extended periods of time. I find it annoying to have a batch constantly open, so looked for a way to hide it and settled on this short piece of VBS:
This is is exactly what I needed and it makes things a lot easier, with one exception. While using this VBS, I can't pass variables to my batch... or to be more precise don't know how to.
My intention is to make several shortcuts with different variables like so:
C:\start.vbs "My variable"
I want to be able to pass "My variable" to my batch, but still be able to manually launch start.vbs without any variable in a way that won't pass a random variable if it is not defined. Passing a blank variable is fine.
I have tried searching for a solution on Google, but being a total newbie to VBS, I couldn't find the right solution. Any help would be highly appreciated. Thanks in advance.
It seems every time I try that, no matter the method I use to pass the variable, the PARAM1 variable doesn't end up being the variable, but just stays PARAM1.
I created a simple batch for the sake of testing my VBS. Batch only has one line, consisting of:
echo Parameteter = %1> Var.txt
The batch writes whatever variable the VBS passes into a TXT. It's an easy way for me to check if the variable has been passes correctly. So, this is the problem I see. No matter what I try, the TXT file says:
When I double click shortcut.lnk, I get the following error:
In this case, Var.txt is not even created, so it does not even reach the part where it's supposed to start the batch. I have no clue what is wrong as I am very inexperienced in VBS. Thanks for your help.
That's a good "catch all" method, but would be cleaner if you named your arguments rather than using the "blanket" arguments collection containing all args that forces you to use For Each to break it up.
I.E. WScript.Arguments(0) or WScript.Arguments(1)
That's why you were getting an error saying "wrong number of arguments".
In defense of my first post: I always focus on syntax errors first as it's usually the most likely suspect