robertejamison
asked on
Using run method with arguments gives "Expected end of statement"
I have a script thate passes a few commands to pesexec. I have the script reading a text file fine, but I have the need to have the script wait until the shell command is complete before proceeding. The lines that are giving me problems are below:
set fso=createobject("scriptin g.filesyst emobject")
Set ots=fso.opentextfile(CompL istPath)
do While not ots.atendofstream
strComputer = ots.readline
strCommand1 = "psexec \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & "" -p " & OldDomainPass & "" cmd /c net user someadmin somepassword /add", 1, True
strCommand2 = "psexec \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & " -p " & OldDomainPass & " cmd /c net localgroup administrators someadmin /add"
Set WshShell = CreateObject("WScript.Shel l")
WshShell.Run strCommand1
Wscript.Sleep(2000)
WshShell.Run strCommand2
Loop
ots.close
The specific line is :
strCommand1 = "psexec \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & "" -p " & OldDomainPass & "" cmd /c net user someadmin somepassword /add", 1, True
If I take the , 1 , True out it works fine, but I need it to wait until the shell dies before proceeding. I am convinced it has something to do with the " marks or () but I am not sure what,
I hope someone can help!
set fso=createobject("scriptin
Set ots=fso.opentextfile(CompL
do While not ots.atendofstream
strComputer = ots.readline
strCommand1 = "psexec \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & "" -p " & OldDomainPass & "" cmd /c net user someadmin somepassword /add", 1, True
strCommand2 = "psexec \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & " -p " & OldDomainPass & " cmd /c net localgroup administrators someadmin /add"
Set WshShell = CreateObject("WScript.Shel
WshShell.Run strCommand1
Wscript.Sleep(2000)
WshShell.Run strCommand2
Loop
ots.close
The specific line is :
strCommand1 = "psexec \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & "" -p " & OldDomainPass & "" cmd /c net user someadmin somepassword /add", 1, True
If I take the , 1 , True out it works fine, but I need it to wait until the shell dies before proceeding. I am convinced it has something to do with the " marks or () but I am not sure what,
I hope someone can help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks gnoon and Rob,
Gnoon's solution worked great, and Rob gave me something I hadn't thought of that enhanced my script even further. Thanks guys!
Gnoon's solution worked great, and Rob gave me something I hadn't thought of that enhanced my script even further. Thanks guys!
WshShell.Run(strCommand1, 1, True)