How to add a registry key with default value containing double quotes and percent sign?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to add a registry key with default value containing double quotes and percent sign?



I can't run successfully a batch file with this content:


REG ADD HKEY_CLASSES_ROOThlpfileshellcompresscommand /d "compact.exe /C "%1"" /f

REG ADD HKEY_CLASSES_ROOThlpfileshelluncompresscommand /d "compact.exe /U "%1"" /f



It results in output of the error message:



Error: Invalid command-line parameters.



I want to create context menu elements and specify actions on Windows XP SP2:


[HKEY_CLASSES_ROOThlpfileshellcompress]

[HKEY_CLASSES_ROOThlpfileshellcompresscommand]
@="compact.exe /C "%1""

[HKEY_CLASSES_ROOThlpfileshelluncompress]

[HKEY_CLASSES_ROOThlpfileshelluncompresscommand]
@="compact.exe /U "%1""



What is wrong with the two command lines in batch file?





See the answer and linked answer in this question stackoverflow.com/questions/2123762/…
– user4317867
Dec 19 '14 at 0:04




1 Answer
1



Use following to overwrite the default value of each registry key or to create each registry key and add the default value from command line:


REG ADD HKEY_CLASSES_ROOThlpfileshellcompresscommand /ve /d ""C:Full Pathcompact.exe" /C "%1"" /f
REG ADD HKEY_CLASSES_ROOThlpfileshelluncompresscommand /ve /d ""C:Full Pathcompact.exe" /U "%1"" /f



Doing the same from within a batch file requires:


@echo off
%SystemRoot%System32reg.exe ADD HKEY_CLASSES_ROOThlpfileshellcompresscommand /ve /d ""C:Full Pathcompact.exe" /C "%%1"" /f >nul
%SystemRoot%System32reg.exe ADD HKEY_CLASSES_ROOThlpfileshelluncompresscommand /ve /d ""C:Full Pathcompact.exe" /U "%%1"" /f >nul



To add a registry value and not only a registry key it is always necessary to specify either /ve for the default value of the key or /v "Name of Value" plus the type of the registry value and of course the value to assign to the registry value.


/ve


/v "Name of Value"



In a batch file a percent sign % must be escaped with an additional percent sign for being interpreted as literal character by Windows command processor parsing the command line before executing the command, application or script. The reason is that % has a special meaning in batch files as it can be seen on running in a command prompt window:


%


%


call /?


for /?


set /?



Please note that command REG parses the arguments different to most other console applications or internal commands of cmd.exe. A double quote " is not interpreted as end of argument string if there is a backslash left to the double quote. In this case the double quote is interpreted as literal character and the backslash left to it as escape character for the double quote. It is necessary to escape a backslash at end of a string value with one more backslash to add the data string correct.


cmd.exe


"



Example:


reg add HKCUEnvironment /v "Please Delete" /t REG_SZ /d "Please delete this variable with a backslash inside and ending with a backslash\"



This command adds the environment variable Please Delete with string value Please delete this variable with a backslash inside and ending with a backslash to persistent list of current user environment variables. A backslash inside the data value string must not be escaped.


Please Delete


Please delete this variable with a backslash inside and ending with a backslash



Please note that environment variables should be added with command SETX to Windows registry and not with command REG as done by the example above if %SystemRoot%System32setx.exe exists.


%SystemRoot%System32setx.exe






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS