6

Is it possible to open files as administrator from inside Emacs on windows?

In Linux one can use tramp to open as administrator, by opening file with following path (/sudo::/path/to/file)?

However, the same file path fails to work in Windows (naturally). How can one request an elevation of privileges for a single file during Emacs session then?

If possible, I would like to avoid launching Emacs as administrator.

Possibly one must do some setup in Windows for that - which, if any? Maybe something like privileged network access?..

Raystafarian
  • 21,963
  • 12
  • 64
  • 91
Srv19
  • 461

2 Answers2

0

I don't think there is a native way to do it, so I am relying on a 3rd-party tool: http://code.kliu.org/misc/elevate whenever i need to do this.

c:\elevate runemacs filename.txt

Enter your credentials in the UAC dialog box and your program will be run with administrative rights.

Terje Mikal
  • 5,287
-1

An unelevated program cannot edit files requiring elevated administrator permissions.

Although a program in Windows can elevate its own permissions through legitimate Windows API (subject to the famous dialog), this requires code that is not part of Emacs, unless you are comfortable with modifying its source-code.

One solution for non-admin Emacs to edit admin files, is to make a copy of the Emacs executable and mark it as "Run as administrator" in file Properties / Compatibility, then launch that copy from Emacs for editing these files.

There are other methods for running an elevated program, including using the Windows runas command, which can also be used from a .bat file. These methods will not require making a copy of Emacs.

harrymc
  • 498,455