How can I edit system files in Windows Vista/7 from Explorer?

3

3

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?

gilbertc

Posted 2009-09-29T16:12:22.117

Reputation: 155

Answers

1

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.

Joshua

Posted 2009-09-29T16:12:22.117

Reputation: 4 434

But then when I open a user file I need to click yes to UAC as well? – gilbertc – 2009-09-29T18:52:57.207

Yes, but then you won't have to remember to launch the program beforehand. – Joshua – 2009-09-29T20:29:10.600

that nppcm.dll error is ugly. but i guess it is notepad++ issue. – gilbertc – 2009-09-29T21:28:45.067

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 – 2009-09-30T07:03:18.360

@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 – 2009-09-30T13:41:23.593

2

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.

Molly7244

Posted 2009-09-29T16:12:22.117

Reputation:

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 – 2009-09-29T16:52:59.273

that's right. will edit my answer accordingly. – None – 2009-09-29T17:19:55.070