stephenlecomptejr
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
On line 2, change to:
strUser = environ("ComputerName") & "\administrator"
strUser = environ("ComputerName") & "\administrator"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
...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.e xe"
strPass="zzzzzzz"
set WshShell=CreateObject("WSc ript.Shell ")
strUser=WshShell.Environme nt("Comput erName") & "\Administrator"
WshShell.Run "runas.exe" & " /user:" & strUser & " " & strCmd
strCmd= "C:\Users\nnnnnn\Documents
strPass="zzzzzzz"
set WshShell=CreateObject("WSc
strUser=WshShell.Environme
WshShell.Run "runas.exe" & " /user:" & strUser & " " & strCmd
ASKER
actually would like instead to have this post deleted.
ASKER
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.
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)