Reputation: 483
I wonder how do I run a .bat or .cmd file as an administrator within a folder where the name contains the same Ampersand "&"? every time I try to run the file appears an error ... at what I did when I try to run as administrator cmd understand that & the folder name is a command.
Let me illustrate, I have a folder called Projects in Cmd & vbs and a file called Project 01.bat when I try to run it as administrator until an error occurs q I remove it from the folder that contains the "&" if the Cmd & vbs.
Folder name: Cmd & Vbs
Script name: Project 01.bat
Form of execution: Option “Run as administered” in the context menu
Version of windows: 7
@Echo Off
Title Remover - [WMP] Buy online music
Color 4f
reg delete "HKEY_CLASSES_ROOT\SystemFileAssociations\Directory.Audio\shellex\ContextMenuHandlers\WMPShopMusic" /f>nul 2>&1
echo msgbox"Removed!",vbinformation> %temp%\Msg.vbs
start /wait %temp%\Msg.vbs>nul 2>&1
Del %temp%\Msg.vbs>nul 2>&1
Exit
Upvotes: 0
Views: 516
Reputation: 483
I discovered that this problem is in runas configuration and the correction is below:
Browse the regedit to:
HKEY_CLASSES_ROOT\batfile\shell\runas\command
HKEY_CLASSES_ROOT\cmdfile\shell\runas\command
Changes the value:
%SystemRoot%\System32\cmd.exe /C "%1" %*
To:
%SystemRoot%\System32\cmd.exe /C ""%1"" %*
Upvotes: 1
Reputation: 2448
Bill is correct, for DOS to work with the &
character, you need to escape it using ^
an example might help:
C:\Temp>cd my&test The system cannot find the path specified. 'test' is not recognized as an internal or external command, operable program or batch file.
C:\Temp>cd my
^
&testC:\Temp\my&test>
Upvotes: 1