Solved

vbs script that opens another .exe file with another username

Posted on 2014-03-24
6
265 Views
Last Modified: 2014-04-01
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
Comment
Question by:stephenlecomptejr
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 39951924
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
 
LVL 12

Expert Comment

by:jkaios
ID: 39957498
On line 2, change to:

strUser = environ("ComputerName") & "\administrator"
0
 
LVL 1

Accepted Solution

by:
stephenlecomptejr earned 0 total points
ID: 39957503
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 12

Expert Comment

by:jkaios
ID: 39957519
...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
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 39957553
actually would like instead to have this post deleted.
0
 
LVL 1

Author Closing Comment

by:stephenlecomptejr
ID: 39966121
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question