Solved

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

Posted on 2007-04-03
13
120 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
  • 7
  • 6
13 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Try:

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

Author Comment

by:mattolan
Comment Utility
still comes up as notepad
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
 
LVL 67

Expert Comment

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

Author Comment

by:mattolan
Comment Utility
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
Comment Utility
Is your script named runas.vbs?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Author Comment

by:mattolan
Comment Utility
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
Comment Utility
my script is named test.vbs
0
 
LVL 2

Author Comment

by:mattolan
Comment Utility
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
Comment Utility
is there any batch file or script named 'runas.*' anywhere on your drive?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
Happy to help! :^)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
With the shift in today’s hiring climate (http://blog.experts-exchange.com/ee-blog/5-tips-on-succeeding-in-the-new-gig-economy/?cid=Blog_031816), many companies are choosing to hire freelancers to get projects completed efficiently and inexpensively…
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

743 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

13 Experts available now in Live!

Get 1:1 Help Now