Link to home
Start Free TrialLog in
Avatar of robertejamison
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("scripting.filesystemobject")
Set ots=fso.opentextfile(CompListPath)
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.Shell")
    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
Avatar of gnoon
gnoon
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You may need to place them within braces

WshShell.Run(strCommand1, 1, True)
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of robertejamison
robertejamison

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!