Reputation: 993
I have to work on a vbs script. I have to admit that I have only c# experience and no clue about the following, what from my point of view is more SysAdmin Powerhell VBS-scripting.
For what stands 'say' here or in general? vbcrlf seems to be some kind of constant that puts the cursor to the beginning of a new line?
say(vbcrlf)
say("Some text...")
ws.Run "C:\whatever.exe /PACK-* /SEND /Q", , True
say(vbcrlf)
What does the ws.run task here? Just starts and run the scsript.exe?
set ws = CreateObject("Wscript.Shell")
if ucase(right(wscript.fullname,11)) = "WSCRIPT.EXE" then
task = "cscript.exe " & chr(34) & wscript.scriptfullname & chr(34)
ws.run task
wscript.quit
end if
Thank you for any help on that!
Edit:
Problem is that the script runs like a charm on XP, but not on Win7. I think it must have something to do with the spaces in the path. Here is the exact path I'm dealing with. Do I need to enclose them with additional double quotes or is chr(34) the way to go?
ws.Run "C:\Program Files (x86)\whatever.exe /PACK-* /SEND /Q", , True
Edit:
Ok, I got it->
ws.Run """C:\Program Files (x86)\whatever.exe"" /PACK-* /SEND /Q", , True
Upvotes: 0
Views: 692
Reputation: 38755
vbCrLf
is a pre-defined string constant consisting of a carriage return and a linefeed:
>> WScript.Echo Asc(vbCrLf), Asc(Right(vbCrLf, 1))
>>
13 10
see String Constants
say
isn't native VBScript; it must be a user-defined Sub:
>> Sub say(x) : WScript.Echo x : End Sub
>> say "pipapo"
>>
pipapo
(The param list () in your sample violate the rule: Don't use param list () when calling a Sub)
.Run
is a method (function) of the WScript.Shell object; it executes/runs an external process. In your example it is used (as a Sub) to re-start the script with the *c*script.exe host (instead of *w*script.exe).
see WshShell object, .Run method
P.S.
If you use .Run (or. Exec), it is a very good idea to build the first/strCommand parameter into a variable for inspection and tests from a command prompt. The argument "Pointlessly create a variable to use extra memory, slow down the script, and to make script harder to read" became obsolete shortly after clay replaced stone for information storage.
Upvotes: 1
Reputation: 743
'Connects to COM object WScript.Shell
set ws = CreateObject("Wscript.Shell")
'Testing what script engine is running the script, if the GUI one then do the following. wscript object is always available in wscript/cscript run scripts
if ucase(right(wscript.fullname,11)) = "WSCRIPT.EXE" then
'Pointlessly create a variable to use extra memory, slow down the script, and to make script harder to read
task = "cscript.exe " & chr(34) & wscript.scriptfullname & chr(34)
'Run the current script in the console version of the scripting host
ws.run task
'quits the script leaving the console version to run
wscript.quit
end if
Upvotes: 0