• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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

0
stephenlecomptejr
Asked:
stephenlecomptejr
  • 3
  • 2
1 Solution
 
KimputerCommented:
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)
0
 
jkaiosCommented:
On line 2, change to:

strUser = environ("ComputerName") & "\administrator"
0
 
stephenlecomptejrAuthor Commented:
Actually this worked for me:

set WshShell = CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
WinPath = WshEnv("SystemRoot")&"\System32\runas.exe"
cmdString = "runas /profile /user:" & strPCName & "\administrator " & chr(34) & "wscript.exe " & ofName & " " & tmpFolder & chr(34)

WshShell.Run cmdString, 1, True

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jkaiosCommented:
...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
0
 
stephenlecomptejrAuthor Commented:
actually would like instead to have this post deleted.
0
 
stephenlecomptejrAuthor Commented:
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now