This is very interesting...
This code works
Set oShell = CreateObject("WScript.Shell")sCommand = "%comspec% /K ""C:Program FilesOpenSSHbinmkpasswd"" -l >> c:passwd.txt"iMyInt = oShell.Run(sCommand, , True)
However when you try to change c:passwd.txt to c:my temppasswd.txt you need to add quotes however the script failes. I've tested many variations and can't get this to work. It appears you can not use quotes around your parameters.
This Fails
Set oShell = CreateObject("WScript.Shell")sCommand = "%comspec% /K ""C:Program FilesOpenSSHbinmkpasswd"" -l >> ""c:my temppasswd.txt"""iMyInt = oShell.Run(sCommand, , True)
I even tried this and it failed as well.
Set oShell = CreateObject("WScript.Shell")sCommand = "%comspec% /K ""test.vbs"" ""c:my temptest.txt"""iMyInt = oShell.Run(sCommand, , True)WScript.Echo iMyInt
Even this and it failed as well.
Set oShell = CreateObject("WScript.Shell")sCommand = "%comspec% /K ""test.vbs ""c:my temptest.txt"""""iMyInt = oShell.Run(sCommand, , True)WScript.Echo iMyInt
Code for test.vbs WScript.Echo WScript.Arguments(0)
Have Fun
Josiahjosiahwoodhouse@hotmail.com2007-05-24 14:13:38
Command Line
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Command Line
WScript.Shell normally has issues with paths with spaces...not much different than if you typed it from the cmd line. I've used the function and recommended it several times and so it should work considering your command is correctly contructed. If you echo out the cmd it echos this:
%comspec% /K "C:Program FilesOpenSSHbinmkpasswd" -l >> "c:my temppasswd.txt"
If this cmd does not work as it is by manually putting it into the cmd line then the issue is with this and not WScript.Shell.
For example:
joseomjr2007-05-24 15:01:45
%comspec% /K "C:Program FilesOpenSSHbinmkpasswd" -l >> "c:my temppasswd.txt"
If this cmd does not work as it is by manually putting it into the cmd line then the issue is with this and not WScript.Shell.
For example:
Code: Select all
Set oShell = CreateObject("WScript.Shell")
sCommand = "%comspec% /c ipconfig.exe >> " & AddQuotes("c:temptemp 2passwd.txt")
oShell.Run sCommand
Function AddQuotes(strInput)
AddQuotes = Chr(34) & strInput & Chr(34)
End Function
Command Line
There is no problem with your syntax.
On my system that works correctly.
Are you on W2K?
Here is the use at the commandline:
%comspec% /K " "c:my scriptstest.vbs" "c:my scriptstest.txt" "
This should become the following in VBS:
sCommand = "%comspec% /K "" ""c:my scriptstest.vbs"" ""c:my scriptstest.txt"" "" "
Read is outer. Blue is first inner. Black is second inner.
It has to be double wrapped be cause of the extra level of indirection.
It gets unwraped into teh CreateProcess call then gets unwrapped again in teh spawning of %comspec%. Each unwrap removes a layer of quotes so you need two layers. Of course these quotes then have to be doubled to place them inside of a string. If you look at teh string it will have only one set of quotes in teh middle and one on teh outside.
I almost forgot about that "gotcha" when spawning the CMD program. It's documented.
jvierra2007-05-25 14:19:22
On my system that works correctly.
Are you on W2K?
Here is the use at the commandline:
%comspec% /K " "c:my scriptstest.vbs" "c:my scriptstest.txt" "
This should become the following in VBS:
sCommand = "%comspec% /K "" ""c:my scriptstest.vbs"" ""c:my scriptstest.txt"" "" "
Read is outer. Blue is first inner. Black is second inner.
It has to be double wrapped be cause of the extra level of indirection.
It gets unwraped into teh CreateProcess call then gets unwrapped again in teh spawning of %comspec%. Each unwrap removes a layer of quotes so you need two layers. Of course these quotes then have to be doubled to place them inside of a string. If you look at teh string it will have only one set of quotes in teh middle and one on teh outside.
I almost forgot about that "gotcha" when spawning the CMD program. It's documented.
jvierra2007-05-25 14:19:22