[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4607
  • Last Modified:

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.
0
bagz1
Asked:
bagz1
  • 2
2 Solutions
 
VorenusCommented:
You can use the SET command for this :

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

C:\>echo %Username%
mmm

If you are looking for something more graphical, you can have a look at the AutoIT scripting language : http://www.autoitscript.com/autoit3/
0
 
Farhan KaziSystems EngineerCommented:
@ECHO OFF
SET /P UserName=Enter username:
RunAs.exe /user:%UserName% "explorer.exe /separate"


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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now