It is advisable to call applications like reg
not being an internal command of Windows command processor cmd.exe
in batch files always with full path and with file extension instead of just file name.
@echo off
%SystemRoot%\System32\reg.exe ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Server" /v DisplayName /t REG_SZ /d Server /f
With using just REG
it depends on which file extensions for executables/scripts are defined in environment variable PATHEXT of current command process and which directories are defined in environment variable PATH of current command process. The order of directories is in this case also important.
See answer on Where is “START” searching for executables? for more details about search for executable. But please note that although start is for all Windows NT based Windows an internal command of command processor cmd.exe
, command processor itself uses only PATHEXT and PATH and ignores App Paths keys in Windows registry. The file searching behavior of Windows command interpreter is explained even more detailed in answer on What is the reason for '...' is not recognized as an internal or external command, operable program or batch file?
The infinite loop is most likely caused by naming the batch file reg.bat
as supposed already by Dennis van Gils. So command processor finds in current directory on searching for an executable with name REG
the file reg.bat
which is already processed and continues batch processing on this batch file with passing the other strings as parameter to reg.bat
. In other words the batch file starts itself again and again in an endless loop.
One more note:
The console application reg.exe
should be used here to add a string value to registry hive HKEY_LOCALE_MACHINE. This write operation for entire machine requires administrator privileges. Therefore either user account control (UAC) is disabled for current user using this batch file or Run as Administrator respectively Runas is used on executing this batch file. Otherwise reg.exe
fails to add the string value to registry because of missing permissions.