Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-04-03
13
Medium Priority
?
135 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
Technology Partners: 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 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Finding a job can be stressful - searches, resume tweaks, and networking events can be super boring. Luckily we're here to help you land your dream job!
Whether you believe the “gig economy,” as it has been dubbed, is the next big economic paradigm shift (https://www.theguardian.com/commentisfree/2015/jul/26/will-we-get-by-gig-economy) or an overstated trend (http://www.wsj.com/articles/proof-of-a-g…
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…

705 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