I've resolved the question I had about inserting %DATE% into a REG_SZ registry value (see link), but now I'm running into a slightly different problem trying to insert %~DP0 (long source path) into a registry value using REG ADD within a .BAT script. It won't do it, and I'm sure it's because I'm doing something wrong.
reg add "hklm\software\acme" /v "TestValue" /d "%~dp0" /t REG_SZ /f
I've also tried setting the value to a variable first, but that doesn't work either. What happens is that it inserts the expanded path without the preceeding double-quote, but with a trailing double-quote, and then bombs with an error about REG /? syntax, etc.
SET VX=%~DP0
reg add "hklm\software\acme" /v "TestValue" /d "%VX%" /t REG_SZ /f
Anyone see what I'm doing wrong?
The path %~dp0 ends in the directory separator character '\' (e.g. 'c:\temp\') which is being interpreted as an escape for the following double-quote character and so the parser is not seeing the closing double-quote. What you need to do is escape the trailing \ character with another one:
reg add "hklm\software\acme" /v "TestValue" /d "%~dp0\" /t REG_SZ /f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With