Link to home
Start Free TrialLog in
Avatar of mattolan
mattolanFlag for Canada

asked on

using runas to launch a cmd window from a vbs with unexpected result.

I am trying to create a vbs script that will launch a cmd window under an admin user account while a user is logged in. the problem I have is that when I combine the .Run command with the runas command I am getting strange results. my code is below. the strangeness is that no matter what I place after the runas the ouput is alwas /user:domain\administrator "notepad". I can type in complete junk like "lksjdjfo32445@345" and the output is still /user:domain\administrator "notepad".
could anyon tell me what is happening so I can correct this?

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:domain\administrator cmd.exe", 9
Avatar of sirbounty
sirbounty
Flag of United States of America image

Try:

WshShell.Run "cmd /c runas /user:domain\administrator cmd.exe"
Avatar of mattolan

ASKER

still comes up as notepad
this worked for me...

wshShell.Run "cmd /k runas /user:domain\username notepad"

The /k states to leave the command window open after processing.../c closes it afterwards...

Not sure what you mean that it still comes up as notepad?
can you post a screenshot?
www.ee-stuff.com is an upload site...
what I mean is that I enter
WshShell.Run "cmd /c runas /user:domain\administrator cmd.exe" in my vbs script but it outputs
runas /user\domain\administrator "notepad" instead.

it doesnot matter what I put after the runas portion of the command the results are always

/user\domain\administrator "notepad"
Is your script named runas.vbs?
this code
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:domain\administrator cmd.exe", 9
or this code
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas asdfh4567$%^%&",9

will both generates this output

c:\>runas /user\domain\administrator "notepad"
Enter the password for domain\administrator:
my script is named test.vbs
if I used the command from the cmd prompt it works, but as soon as I combine it with the WshShell.Run command it doesn't work
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm thinking that's coming from somewhere else...
Even when I use your example and don't use cmd /c
the 'only' think I get at the prompt is to enter the password...
that was it exactly I had an old file sitting on my destop called runas.bat.
I deleted it and the command works perfectly. glad you asked that question becuase I don't think I would have found that any time soon
Happy to help! :^)