The folder name of my folder contains the ampersand symbol "&", and in that folder i have at batchfile, batchfile.bat.
Lets say the path is:
C:\Users\%username%\Desktop\1 & 2\batchfile.bat
When creating af shortcut to run that batchfile, when not run as administrator, it works. But as soon as i run the shortcut as administrator, it will not open batchfile.bat and gives the error:
'C:\Users\%username%\Desktop\1' is not recognized as an internal or external command,
operable program or batch file.
Is there a way to bypass the ampersand (&), and run the program as administrator, whithout changing the name of the folder?
Adapt the target field of the shortcut from
"C:\Users\%username%\Desktop\1 & 2\batchfile.bat"
to (here /K
switch for debugging purposes, the cmd
window should stay open)
C:\Windows\System32\cmd.exe /K call "C:\Users\%username%\Desktop\1 & 2\batchfile.bat"
and finally to
C:\Windows\System32\cmd.exe /C call "C:\Users\%username%\Desktop\1 & 2\batchfile.bat"
Tested with simplified path "D:\bat\1 & 2\batchfile.bat"
as follows:
The script is as follows:
@ECHO OFF >NUL
@SETLOCAL enableextensions
set "xx=%~f0"
echo stackoverflow 28077086 %xx:&=^&%
@ENDLOCAL
goto :eof