Archive: WriteRegBin, not working in macros if hex data passed in?


WriteRegBin, not working in macros if hex data passed in?
Hello Everyone,

I am using NSIS 2.0, and I am attempting to write a macro that checks to see if a registry key exists or not, then create or update it where necessary. This works as expected for String or DWord data, but does not function as expected for Binary data.

I get the following information at compile time:

StrCmp "STRING" "HEX" equal=0, nonequal=+2
Usage: WriteRegBin rootkey subkey entry_name hex_string_like_12848412AB
root_key=(HKCR|HKLM|HKCU|HKU|HKCC|HKDD|HKPD)
Error in macro CreateRegVarIfNotExist on macroline 15

The code is pretty simple and breaks down to the following:

xx !MyMacro UPDATE ROOT KEY NAME VALUE
xx ; check if the key exists if not create it
15 WriteRegBin "${ROOT}" "${KEY}" "${NAME}" "${VALUE}"
xx ; If forced update is true, then update it
xx WriteRegBin "${ROOT}" "${KEY}" "${NAME}" "${VALUE}"
xx !macroend

I suspect that the HEX value being passed in which is valid and formatted correctly is not being processed at compile time in regards to being passed as a parameter to the macro.

Could someone verify this, and let me know if there is a work-around or a patch?

Cheers,

ZIMSMS


Works fine for me. Please attach a script that reproduces the problem.

Make sure there are only valid characters: 0-9 and A-F.


Hello, Ok, I figure the cause is not WriteRegBin, however that is what the compiler complains about. When I pass STRING as one of my parameters, it blows up, see the attached script.



Ok, I found out some more by playing around, in the script you'll see I do the following:

!insertmacro CreateRegVarIfNotExist 1 "STRING" HKLM "Software\Modern UI Test" "Dependencies_one" "Hello World!"
!insertmacro CreateRegVarIfNotExist 1 "DWORD" HKLM "Software\Modern UI Test" "Dependencies_two" "Hello World!"
!insertmacro CreateRegVarIfNotExist 1 "HEX" HKLM "Software\Modern UI Test" "Dependencies_three" "48656C6C6F20576F726C6421"


If you remark the first two calls to the macro, then the macro works fine for the third.

Thoughts?


You have one macro that decides which type to use on run-time, using StrCmp. That means that you put all the three options in the installer. If you are using a value that is invalid for one of them, it will fail.

You should set the type on compile-time using a defined symbol.


DOH! Why didn't I try that! :igor: Must be a lack of coffee. Thanks Joost!