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!
robertejamisonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gnoonCommented:
Yes, take it out from the line but place it to the WshShell.Run line instead

strCommand1 = "psexec \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & "" -p " & OldDomainPass & "" cmd /c net user someadmin somepassword /add"
WshShell.Run strCommand1, 1, True
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gnoonCommented:
You may need to place them within braces

WshShell.Run(strCommand1, 1, True)
0
RobSampsonCommented:
gnoon is right, the first comment will do the job.

What you may also need, however, is to explicity run the command in a DOS window. This is what I would use:

Set objFSO = CreateObject("Scripting.FileSystemObject")
strPSExecPath = "C:\Tools\PSExec.exe"
strPSExecPath = objFSO.GetFile(strPSExecPath).ShortPath
strCommand1 = "cmd /c " & strPSExecPath & " -accepteula \\" & strComputer & " -u " & OldDomainName & "\" & OldDomainAdmin & "" -p " & OldDomainPass & "" cmd /c net user someadmin somepassword /add"
WshShell.Run strCommand1, 1, True


Regards,

Rob.
0
robertejamisonAuthor Commented:
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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.