Solved

vbs script that opens another .exe file with another username

Posted on 2014-03-24
6
261 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now