Solved

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

Posted on 2007-04-03
13
130 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:mattolan
[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
  • 7
  • 6
13 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18846441
Try:

WshShell.Run "cmd /c runas /user:domain\administrator cmd.exe"
0
 
LVL 2

Author Comment

by:mattolan
ID: 18846503
still comes up as notepad
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18846534
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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18846536
can you post a screenshot?
www.ee-stuff.com is an upload site...
0
 
LVL 2

Author Comment

by:mattolan
ID: 18846552
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"
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18846567
Is your script named runas.vbs?
0
 
LVL 2

Author Comment

by:mattolan
ID: 18846623
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:
0
 
LVL 2

Author Comment

by:mattolan
ID: 18846627
my script is named test.vbs
0
 
LVL 2

Author Comment

by:mattolan
ID: 18846648
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
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 125 total points
ID: 18846683
is there any batch file or script named 'runas.*' anywhere on your drive?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18846692
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...
0
 
LVL 2

Author Comment

by:mattolan
ID: 18846717
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
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18846727
Happy to help! :^)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Gift cards are not a new concept - it's been around for a very long time.  Undoubtedly, over the past you have received such a card or purchased one for a friend or relative.  Are you aware that you've been feeding the machine?  If not, read on :)
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.

626 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