5

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?..

4
  • possible duplicate of Is there any 'sudo' command for Windows?
    – sashoalm
    Mar 31, 2015 at 7:08
  • 1
    I don't think it's a duplicate. If you open a file that need admin rights to edit with notepad++, the editor can restart in administrator mode. Emacs use sudo on Linux to edit files as administrator. sudo wouldn't necessarily be used on Windows to do the same thing.
    – bbigras
    Nov 12, 2015 at 15:43
  • Yes, there is no sudo on Windows, hence the question
    – Srv19
    Nov 13, 2015 at 11:01
  • I suggest you M-x report-emacs-bug and request it as a new feature for Tramp. If you can use "runas" to start a bash shell running as administrator (and have enough Unixy tools installed), then it should be fairly easy to extend Tramp's "su" and "sudo" support to use "runas".
    – Stefan
    Nov 15, 2015 at 19:21

2 Answers 2

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.

4
  • That doesn't seem to be any different from right-clicking on emacs shortcut and selecting 'Run as administrator'. Do you use that from command line or from inside emacs?
    – Srv19
    Nov 13, 2015 at 11:22
  • From the command line, which is what I assumed you wanted since you were looking for a "sudo"-like command. Nov 13, 2015 at 11:25
  • I was not. To quote myself, i am looking for a way to "open files as administrator from inside emacs".
    – Srv19
    Nov 13, 2015 at 11:53
  • I see. I misread the question and jumped to the wrong conclusion when i read the "sudo" part. Sorry about that :) Nov 13, 2015 at 13:10
-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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.