Configuring a batch file to run apps as another user, with a username and password prompt.

Posted on 2007-10-18
Last Modified: 2012-08-13
We are changing the Network admin password at our company, and providing the individual analysts with their own network Admin accounts.

Currently due to policies/restrictions that are in effect within our company our analysts have to run batch files to access certain areas of our users PC's e.g Control panel, registry.

These batch files allow analysts to access the control panel, registry, local disk as the Network administrator giving them full access.

Example code:
runas.exe /user:domain\Administrator "explorer.exe /separate"

How can I change the code so that the batch file will prompt each analyst to enter their own Admin username and password and access these areas as themselves.
Question by:bagz1
    LVL 4

    Accepted Solution

    You can use the SET command for this :

    C:\>SET /P Username=Enter your username:
    Enter your username:mmm

    C:\>echo %Username%

    If you are looking for something more graphical, you can have a look at the AutoIT scripting language :
    LVL 26

    Assisted Solution

    SET /P UserName=Enter username:
    RunAs.exe /user:%UserName% "explorer.exe /separate"

    RunAs itself will ask for password.

    Author Comment

    I tried using the set command as you suggested.

    SET /P Username=Enter your username:

    Enter your username:

    echo %Username%

    runas.exe /user:%username% "explorer.exe /separate"

    This seems to be working great.

    Thanks for your speedy response Vorenus and a great solution.

    Author Comment

    farhankazi that has made it alot simpler and easy to understand thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
    You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now