?
Solved

vbs script that opens another .exe file with another username

Posted on 2014-03-24
6
Medium Priority
?
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 36

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
Independent Software Vendors: 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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

649 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