XP: Run a program as another user with runas

Contributor Icon Contributed by qmchenry Date Icon April 13, 2004  
Tag Icon Tagged: Windows security

Regardless what operating system you use, it is a dangerous practice to login and perform normal (non-administrative) tasks with administrative privileges. Unwittingly executing a program concealing a trojan horse as an administrator will provide administrative rights to that program and the impact may be much greater.

However, increased security generally causes increased inconvenience. The runas command provides a convenient means of running a program with different credentials, typically as administrator, while working as a less privileged user.


The runas command has many options for its operation. The simplest example is running the command regedit as the user administrator on the local system (which should always be referrable by the name localhost):

runas /user:localhost\administrator regedit

You will be prompted for the password for administrator. If you provide the correct password, the regedit command will start.

To further accomodate laziness, the runas command can be used in a batch file. If you frequently run the regedit command on your system, create a regedit.bat file containing the following text:

@ runas /user:localhost\administrator regedit

Then you can double click on the icon for the batch file you just created to start the regedit (after entering the appropriate password, of course). The @ symbol prevents the commands that follow from being printed to the screen when they are run so the only text in the window that pops up is the password prompt. Dragging the batch file into the start menu or a program group will make it even easier to use.

Previous recipe | Next recipe |
 

 
close Reblog this comment
blog comments powered by Disqus