Page 1 of 1
Script Aid
Posted: Thu Mar 30, 2006 6:25 pm
by PT
Anyone
Anyone know how to send the followng in vb script:-
C:\HB_Control.exe /I 192.168.1.30 /O 8100 /S password /C SPV /D "emailout" /P "Message" /V Yes
???
Posted: Sat Apr 01, 2006 1:38 pm
by PT
Anyone?
Posted: Sat Apr 01, 2006 2:57 pm
by robogeek
It's been a while since I played with vbscript. Something like this... maybe?
Code: Select all
Set wshShell = WScript.CreateObject("WScript.Shell")
wshShell.Run ("C:\HB_Control.exe /I 192.168.1.30 /O 8100 /S password /C SPV /D ""emailout"" /P ""Message"" /V Yes")
Check this link for more info:
wshShell.Run
If the quotes (or other special/reserved characters) within the command line parameters are screwing it up and causing errors, try a google search for
Wshell.Run quotes for tips on how to use quotes within the WScript.Shell Run method.
Posted: Sat Apr 01, 2006 5:21 pm
by PT
Jason
You are a star! Thanks very much for this.
I had been playing with the quotes,commenting out and even linking with ampersand.
I was wondering whether the amount of switches were going to be ok within script. Starting programs were not a problem.
Anyways thanks again, very much appreciated.
PS
Why only comment/quote out the device and property?Is it because they are actual names where the others are actions?
Posted: Sat Apr 01, 2006 5:45 pm
by robogeek
PT wrote:
PS
Why only comment/quote out the device and property?Is it because they are actual names where the others are actions?
Glad it worked :)
To get the original quotes around
emailout and
Message to work inside they need to be double quoted. Think of it like this... this is what the command line would have looked like inside the Run method without the double quotes:
Code: Select all
"C:\HB_Control.exe /I 192.168.1.30 /O 8100 /S password /C SPV /D "emailout" /P "Message" /V Yes"
The individual quotes around
emailout and
Message would mess up the string since the first quote before
emailout isn't really the end of the string. Windows would have treated that first quote before
emailout as the end of that string segment...and the rest would have generated an error. To get one quote to be part of the string, use two quotes instead of one. I hope that explains the quoting mess a little :lol:
Posted: Sat Apr 01, 2006 6:16 pm
by PT
Yep Got That
Thanks again
Posted: Sun Apr 02, 2006 5:17 am
by Richard Naninck
I have it working like this:
Set MyShell = CreateObject( "WScript.Shell" )
CommandString = Chr(34) & "C:\Program Files\Meedio\Meedio HouseBot\Config\Scripts\CNQ Status BatchFile.bat" & Chr(34)
ReturnCode = MyShell.Run (CommandString, 0, True)
For some reason double quotes never work for me so I have to go with Chr(34) & "....." & Chr(34). Anybody knows why that is?
Als without a ReturnCode or whatever label you want to give it, it won't work.
Posted: Sun Apr 02, 2006 7:20 am
by PT
Richard
You can also use triple quotes to achieve the command line
Set MyShell = CreateObject( "WScript.Shell" )
CommandString = """C:\Program Files\Meedio\Meedio HouseBot\Config\Scripts\runa.bat"""
ReturnCode = MyShell.Run (CommandString, 0, True)
edit note
which comes from this note I found
You need to pass a string that actually contains the quoted filename.
Within a literal string, a single double-quote character is represented by two double-quote characters.
Posted: Sun Apr 02, 2006 7:58 am
by Richard Naninck
I never tried tripple quoting, because that actually doesn't make sense to me. I will try it however.
Double quoting, doesn't just work, it produces a script error whereas Chr(34) doesn't. And that doesn't make sense either because Chr(34) is a quote.
Posted: Sun Apr 02, 2006 8:24 am
by PT
It works. Trust me.
I have used it elsewhere and the above worked fine.I admit it does seem strange.
Posted: Sun Apr 02, 2006 10:45 am
by dlmorgan999
This is a tricky subject and I've had issues with both the way that Richard is suggesting and what PT is suggesting. Right now I have a script that has been successful using the CHR(34) method. In theory the triple quote should also work fine because you are quoting the quotes (strange I know).
As for Richard's question about needing ReturnCode that's because you are calling the code as a function rather than a sub. If you call it like the following line it *should* work just fine:
Code: Select all
MyShell.Run CommandString, 0, True
This is the way I use it in one of my scripts. The difference is that when you call as a function you must wrap the parameters in () but when called as a sub you can't (one of the inconsistencies of VB).
-- Dave
Posted: Sun Apr 02, 2006 12:37 pm
by PT
My reply was tongue in cheek! :lol:
Richard is a far better scripter than I.
----------------------
another alternative
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run """C:\Program Files\Meedio\Meedio HouseBot\Config\Scripts\runa.bat""", 6, True
set wshshell = nothing
Posted: Sun Apr 02, 2006 12:51 pm
by Richard Naninck
OK, just tried it and both lines work:
msgbox Chr(34) & "test" & Chr(34)
msgbox """test"""
So tripple quoting works (thanks for the suggestion), but double quoting produces an error like: End of instruction is expected.
As for the ReturnCode, I call many functions without a returncode. I just tried a small example like this:
Call Hello()
Function Hello()
Hello = "Hel_lo"
End Function
There is no returncode in front of it and it doesn't complain.
Another question, now that we are talking about it:
Functions can be called without the keyword Call.
Even functions with a parameter works.
Hello(Flag)
But if I want two parameters to go along, the keyword Call should be in there as well like:
Call Hello(Flag1, Flag2). This won't work without the Call. And now I am getting to my question....
What if the Function Hello(Flag1, Flag2) needs to return something.
Function Hello(Flag1, Flag2)
Hello = "OK"
End Function
Now, how do I Call that Function?????
Call ReturnCode = Hello(Flag1, Flag2) does not work.
ReturnCode = Call Hello(Flag1, Flag2) does not work
ReturnCode = Hello(Flag1, Flag2) does not work because more than one Flag is in the Function call. Below is what really does work:
ReturnCode = Hello(Flag1) because I can call functions without the keyword Call if none or only one flag is in the function.
Hopefully all of the above makes sense and hopefully somebody replies with a simple why this happens and how I can work around it.