Add open with Notepad as Administrator

So often do I work on my laptop or on servers and I have to open a file in Notepad to edit it, however the file is protected so you have to not only be an administrator but you need to use ‘Run as Administrator’

Now that’s all well and good if the menu item is there…  Try right clicking on say your hosts file and look for ‘Run as Administrator’

Run As Normal

After some digging with my favourite Sysinternals tools, I found a very simple registry file can be used to add these kinds of items

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\RunAs]
 "HasLUAShield"=""
 @="Notepad as Administrator"

[HKEY_CLASSES_ROOT\*\shell\RunAs\command]
 @=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
 00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,6e,00,6f,00,\
 74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,00,31,\
 00,22,00,00,00

This adds a great new menu item that will open the file in Notepad and elevates you to Administrative credentials (initiating UAC if needed).  The key is that the bit after \shell\ MUST start with RunAs, but you can add as many as you like!  The hex piece is there as I’m using a REG_EXPAND_SZ to avoid hardcoding the path to Notepad.  HasLUAShield if present will make the UAC shield show on the menu.

I’ve used \shell\RunAs\ above so that for the likes of exe files it doesn’t show the ‘Notepad as Administrator’ option since it has a ‘Run as Administrator’ option set on the exefile.  However if you want both to show then just use say \shell\RunAsNotepad\ and you see both.

So now it looks like this:

Notepad as Admin

Happy days!  Enjoy administrative Notepad rights!

 

 

 

Twan van Beers

Twan is a senior consultant with over 20 years of experience. He has a wide range of skills including Messaging, Active Directory, SQL, Networking and Firewalls. Twan loves to write scripts and get deep and dirty into debugging code, in order to understand and resolve the most complex of problems.

Leave a Reply

Your email address will not be published. Required fields are marked *

Search