Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Windows Vista/7, when I open a system file (say, system32/drivers/etc/hosts) with an editor (I am using Notepad++, but I guess it can be anything else) and make some changes to it, I cannot save the file due to the file is protected.

To edit the file, I need to open the editor with 'Run as Administrator', click yes to UAC, and open the system file from the editor.

Is there any way for me to open the file with my default editor by opening it from explorer with "Run as Administrator", click yes to UAC, and be able to edit and save the file?

share|improve this question
up vote 1 down vote accepted

While Molly's answer is close, if you set the "Run this program as an administrator" on the actual .exe itself (Usually at C:\Program Files\Notepad++ or C:\Program Files (x86)\Notepad++), it'll cause any double clicking on an associated filetype to request elevation.

enter image description here

Keep in mind that this may cause the default "Edit in Notepad++" menu item to break with an error of " Error creating process: nppcm.dll needs to be in the same directory as the notepad++ executable " (at least it did on my default install), but right-clicking on the file, pointing to "Open With" and selecting Notepad++ from there will work.

share|improve this answer
But then when I open a user file I need to click yes to UAC as well? – gilbertc Sep 29 '09 at 18:52
Yes, but then you won't have to remember to launch the program beforehand. – Joshua Sep 29 '09 at 20:29
that nppcm.dll error is ugly. but i guess it is notepad++ issue. – gilbertc Sep 29 '09 at 21:28
This is terrible... You have Notepad++ running in elevated mode all the time. Talk about bad security design from MS... people are still forced to resort to hacks like this to make simple things work. The proper solution to this problem would have been for the OS to ask for elevation permission when needed - ie, right when Notepad++ needs to write a protected file. Elevating it all the time is precisely the wrong thing to do... but the only solution I guess in Win7 – Zoran Sep 30 '09 at 7:03
@Zoran: I agree, in fact I don't run this way myself. If I have to edit a system file, I go to the file in Explorer, shift-right-click on the file and select "Copy as Path". I use that path to open the file in a manually elevated Notepad++. As a developer I understand the reasons for not allowing drag and drop between security boundaries and the purpose of elevation but not every one is willing to work with the operating system. In this case, I would prefer someone to run a program like this elevated all the time rather than turning UAC off completely. The lesser or two evils I suppose. – Joshua Sep 30 '09 at 13:41

You may not want to run your editor permanently with elevated rights (as it will add to the inconvenience when you run into UAC anytime you're using it).

So, create a new shortcut, for example:

C:\WINDOWS\system32\notepad.exe C:\WINDOWS\system32\drivers\etc\hosts

Right-click the new, and then click Properties.

On the Shortcut tab, click Advanced.

Select the Run as administrator checkbox.

alt text

This will open your Notepad with the HOSTS file as administrator.

share|improve this answer
This will only work with that particular shortcut, and will not open the editor with elevated rights from any other method, including context menus. – Jared Harley Sep 29 '09 at 16:52
that's right. will edit my answer accordingly. – Molly7244 Sep 29 '09 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .