Script Aid

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
PT
Senior Member
Posts: 147
Joined: Wed Apr 13, 2005 12:32 pm
Location: Hampshire.UK

Script Aid

Post 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

??? :?
Regards

PT

If it isn't broke,fix it till it is!
PT
Senior Member
Posts: 147
Joined: Wed Apr 13, 2005 12:32 pm
Location: Hampshire.UK

Post by PT »

Anyone?
Regards

PT

If it isn't broke,fix it till it is!
robogeek
Member
Posts: 2
Joined: Wed Apr 09, 2003 5:14 pm
Location: Appleton, WI
Contact:

Post 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.
--Jason (aka robogeek)

My Themes
PT
Senior Member
Posts: 147
Joined: Wed Apr 13, 2005 12:32 pm
Location: Hampshire.UK

Post 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?
Regards

PT

If it isn't broke,fix it till it is!
robogeek
Member
Posts: 2
Joined: Wed Apr 09, 2003 5:14 pm
Location: Appleton, WI
Contact:

Post 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:
--Jason (aka robogeek)

My Themes
PT
Senior Member
Posts: 147
Joined: Wed Apr 13, 2005 12:32 pm
Location: Hampshire.UK

Post by PT »

Yep Got That :D

Thanks again
Regards

PT

If it isn't broke,fix it till it is!
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Post 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.
PT
Senior Member
Posts: 147
Joined: Wed Apr 13, 2005 12:32 pm
Location: Hampshire.UK

Post 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.
Regards

PT

If it isn't broke,fix it till it is!
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Post 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.
PT
Senior Member
Posts: 147
Joined: Wed Apr 13, 2005 12:32 pm
Location: Hampshire.UK

Post by PT »

It works. Trust me. :wink:

I have used it elsewhere and the above worked fine.I admit it does seem strange.
Regards

PT

If it isn't broke,fix it till it is!
dlmorgan999
HouseBot Special Member
Posts: 409
Joined: Tue Jul 13, 2004 9:13 am
Location: Tigard, OR

Post 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
PT
Senior Member
Posts: 147
Joined: Wed Apr 13, 2005 12:32 pm
Location: Hampshire.UK

Post 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
Regards

PT

If it isn't broke,fix it till it is!
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Post 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.
Post Reply