Link to home
Start Free TrialLog in
Avatar of stephenlecomptejr
stephenlecomptejrFlag for United States of America

asked on

vbs script that opens another .exe file with another username

All this script when ran does ask for a password but when I enter it - the .exe program never is ran.   Please let me know how I may change it to actually open and run the program!

strCmd= "C:\Users\nnnnn\Documents\asdasd.exe"
strUser=".\administrator"
strPass="sssssss"
set WshShell=CreateObject("WScript.Shell")
WshShell.Run "runas.exe" & " /user:" & strUser & " " & strCmd

Open in new window

Avatar of Kimputer
Kimputer

use cscript to run the script, so you can follow up on the actual error message

alternatively, use psexec (which allows you to input the password already, so you don't have to input it manually, if it's not a security risk in this situation)
On line 2, change to:

strUser = environ("ComputerName") & "\administrator"
ASKER CERTIFIED SOLUTION
Avatar of stephenlecomptejr
stephenlecomptejr
Flag of United States of America 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
...correction, move line 2 to after line 4, but change from the non-recognize Environ function to the shell's Environment method as follows:

strCmd= "C:\Users\nnnnnn\Documents\adasdad.exe"
strPass="zzzzzzz"
set WshShell=CreateObject("WScript.Shell")
strUser=WshShell.Environment("ComputerName") &  "\Administrator"
WshShell.Run "runas.exe" & " /user:" & strUser & " " & strCmd
Avatar of stephenlecomptejr

ASKER

actually would like instead to have this post deleted.
The question was addressing how I may change the syntax for this to work.  It wasn't a recommendation on trying cscript versus WshShell and it really wasn't a matter of finding the computer name/user by another coding method.