When running a simple batch file (.cmd) as administrator (Rightclick --> Run as administrator), it just flashes by in the taskbar and nothing more is happening.
Running the file by just doubleclicking on it works fine.
Total content of the .cmd file:
@echo off
set /p DUMMY=Done executing...
No logs in the eventviewer or error messages that I have found... Any ideas what to try?
Characters like space, ampersand, pipeline etc. have a special meaning in Windows command line and should be escaped. Right-click Run as administrator action could be defined for a particular executable file type (extension in
PATHEXT
variable) in corresponding registry keys - such as inHKEY_CLASSES_ROOT\cmdfile
andHKEY_CLASSES_ROOT\batfile
for Windowscmd
scripts:Right-click Run as administrator actions for these file types are originally defined as follows:
Unfortunately, the double quotes are stripped out (see
cmd /?
):Hence, we need to invoke the following command instead:
To do that, open an elevated command prompt and run the following commands (run the
reg add
command forbatfile
as well, mutatis mutandis):If you prefer doing that from a
.bat
or.cmd
script, then thereg add
command should read as follows:It is because of the path the file is located in. The path cannot contain an "&" sign, and also a combination of "@" and a space doesn't work either:
C:/temp/test.cmd - Works!
C:/temp&/test.cmd - Doesn't work!
C:/temp &/test.cmd - Doesn't work!
C:/temp@/test.cmd - Works!
C:/temp @/test.cmd - Doesn't work!
Makes sense right? :) Windows bug...