Skip to content
⌘ NSIS Forum Archive

overwrite regkeys

11 posts

aemik#

overwrite regkeys

hello,

i use "overwrite off" for my "file" commands.
can i also use it "writeregstr ..." ?
i dont want to overwrite regkeys. is it possible?
Anders#
no, but you can try to read it first, and only write if it sets the error flag (or returns empty string)
aemik#
I have a long list (50) of RegKeys like this:

WriteRegStr HKLM "Software\x\x" "abc" "def"
...
WriteRegStr HKLM "Software\x\x" "asd" "gfd"


I only want to write them if they not exist. Can you please give me the code for this problem??

Thnaks for your help
aemik
pospec#
Yes, I can. Sorry for that Czech names 😉

I can also provide script which converts .reg file into NSIS commands like ${registry::________} ... ... ... ...
pospec#
The script was too big.
aemik#
thank you for help.

How can i include this script and how can i use it for my registry keys?
pospec#
Copy / paste?

Try something like ${ZapisReg} "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion" "ProductId" "this is really CRAP!" "REG_SZ"
Afrow UK#
Just use a macro:
!macro _WriteReg Type Root Key Name Value
Push $R0
ClearErrors
ReadReg${Type} $R0 `${Root}` `${Key}` `${Name}`
Pop $R0
IfErrors 0 +2
WriteReg${Type} `${Root}` `${Key}` `${Name}` `${Value}`
!macroend

!define WriteRegDWORD `!insertmacro _WriteReg DWORD`
!define WriteRegBin `!insertmacro _WriteReg Bin`
!define WriteRegStr `!insertmacro _WriteReg Str`
${WriteRegDWORD} HKLM `Software\MyApp` `Blah1` 1
${WriteRegBin} HKLM `Software\MyApp` `Blah2` ABCD
${WriteRegStr} HKLM `Software\MyApp` `Blah3` Hello

Edit: shortened.

Stu