22:54 - Thursday, 24 April 2014

“Run As” For A .bat File

#Topics: run bat as a different user,run bat file as a different user,runas batch reg

I’d like to run a .bat file as a different user to troubleshoot a rights problem which I suspect.

For normal .exe files, you can Shift-right-click to get “Run as…”. However, for a .bat file, this does not work (Shift-right-click gives no menu entry “Run as…”). Why is that so, and how can I “Run as” a .bat file? Is it possible at all?

System is Windows XP SP2 Home Edition.

Use the command line. For example,

runas /noprofile /user:COMPUTERNAMEUSERNAME "C:MYBAT.bat"

See more about the command in the reference documentation for Runas.

To add the Run as… option for .BAT files to the context menu, use the following REG file:

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOTbatfileshellrunascommand]@=""%1" %*"

Copy the above contents to Notepad, and save the file with .REG extension (say, bat_runas.reg). Right-click the .REG file and choose Merge.

To add the Run as… menu for .CMD files, use this REG file:

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOTcmdfileshellrunascommand]@=""%1" %*"

Copy the above contents to Notepad, and save the file with .REG extension (say, cmd_runas.reg). Right-click the .REG file and choose Merge.

Share

Advertisement

Comment