Avatar of bryanpilger
bryanpilger
Flag for United States of America asked on

Need assistance in using psexec in vbscript

I am trying to use psexec in my vbscript to run certain programs as an administrator.
Lets take cmd prompt for example. I use the psexec command to open the cmd prompt on the local machine as using admin credentials. The problem is that it opens up, but then closes right away. Here is the code I am using

objShell.Exec ("psexec.exe \\" & strComputerName & "-u " & strUsername1 & "-p " & strPassword & "cmd.exe")

Is there an argument I can use or something to do this?
Visual Basic ClassicVB ScriptProgramming

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
sirbounty

psexec.exe is presumably in your path?
If not, specify the full path:

objShell.Exec ("c:\pstools\psexec.exe \\" & strComputerName & "-u " & strUsername1 & "-p " & strPassword & "cmd.exe")

Open in new window

sirbounty

Could also be the missing space  
objShell.Exec ("psexec.exe \\" & strComputerName & " -u " & strUsername1 & " -p " & strPassword & "cmd.exe")

Open in new window

RobSampson

You are missing the spaces....

Try this.

Regards,

Rob.
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPSExec = "C:\Temp\PSExec.exe"
strPSExec = objFSO.GetFile(strPSExec).ShortPath
strComputer = "compname"
strUser = "user"
strPass = "pass"
strCmd = "cmd /k " & strPSExec & " -accepteula " & " \\" & strComputer & " -u " & strUser & " -p " & strPass & " cmd.exe"
objShell.Run strCmd, 1, True

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
bryanpilger

ASKER
Thanks Rob. That worked really well!

One more thing though. Is there anyway to get the vbscript to continue going instead of waiting for psexec to be done. Also, when I run this command, it opens up the psexec cmd window, and the cmd window that psexec opened up. Is there any way I can make it so that the psexec window is hidden, or make it close when I close the cmd window?
ASKER CERTIFIED SOLUTION
RobSampson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
bryanpilger

ASKER
Wow. Thats great. Thanks Rob!!! Works like a charm now!
RobSampson

No problem . Thanks for the grade.

Regards,

Rob.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.