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

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.
Who is Participating?
VorenusConnect With a Mentor Commented:
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 :
Farhan KaziConnect With a Mentor Systems EngineerCommented:
SET /P UserName=Enter username:
RunAs.exe /user:%UserName% "explorer.exe /separate"

RunAs itself will ask for password.
bagz1Author Commented:
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.
bagz1Author Commented:
farhankazi that has made it alot simpler and easy to understand thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.