The usual way to run program under Administrator privileges is via menu Run as Administrator.
In order to run program as Administrator from batch file you have an option to use runas
Windows
utility. Unfortunately its option /user:...
takes account name and Administrator account name is
a subject of localization so it depends on Windows edition...
Cygwin comes with cygstart
utility and with --action=runas
option you can start program with
administrator privileges.
I maintain special script e
that is used to invoke emacsclient
with convenient behavior. For
example for Cygwin emacs-w32
it makes special steps to hide console window.
I made decision to improve e
script so it would ask for Administrator privileges.
Because granting administrator privileges under Windows UAC mean that you will have a dialog with conformation in order to see this dialog only once I need to start only main Emacs server under this condition.
Because core part of e
script is just invocation of emacsclient
with -a ...
option to
start Emacs server if it absent the only way to start Emacs by cygstart
is by supplying wrapper
script to -a
option. Because I don't want to maintain and install additional script I told
emacsclient
to invoke e
itself and guard from infinite invocation loop by setting
environment variable.
I start Emacs by Win+R
then e
and Enter
. Windows doesn't understand sh-scripts, so it
starts e.bat
. And if emacsclient-w32
can't find running Emacs server it calls my e
sh-script which start emacs-w32
by cygstart --action=runas
.
So e.bat
has:
for %%X in (emacsclient-w32.exe) do (set FOUND=%%~$PATH:X) if defined FOUND ( rem Cygwin Emacs-w32. set RUNEMACSARG=-a e set EMACSCLIENT=run --quote emacsclient-w32 set MAKECYGEMACSADMIN=yes ) %EMACSCLIENT% %RUNEMACSARG% %args% .
and e
has:
if [[ "$MAKECYGEMACSADMIN" = yes ]]; then unset MAKECYGEMACSADMIN exec cygstart --action=runas run emacs-w32 fi
Complete solution available at: http://hg.defun.work/utils/file/tip/emacs
Other scenarios of usage e
script as documented in man page aren't changed.