- NSIS Discussion
- Help with registry needed
Archive: Help with registry needed
Vitaly
18th December 2006 12:18 UTC
Help with registry needed
Urgently need help with registry writing...
I'm not too good at this NSIS thing yet, still learning, and my understanding of making system calls via System:: is a bit vague. And i'm faced with a task that requires to take current date/time from the system, and save it in the windows registry as Binary of automated type DATE.
It took me half day to come up with the code to get time/date in the DATE format, using the following:
System::Call /NOUNLOAD '*(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2) i .r1'
System::Call /NOUNLOAD 'kernel32::GetSystemTime(i)i(r1)'
System::Call /NOUNLOAD 'Oleaut32::SystemTimeToVariantTime(i r1, *l .r0) i .r3'
System::Free $1
;Now I have correct DATE in $0, i hope. But to put it into registry as binary is yet another problem, since WriteRegBin doesn't allow me to do that, as i understand, i.e. it only works with text strings for some weird reasons...
Anybody, please help with this task, how to put DATE (which is 64 bit) into registry as binary?
Great thanx in advance!!!
Red Wine
18th December 2006 12:44 UTC
You need the Registry Plugin to write QWORD (64 bit) data.
EXAMPLE:
!include "Registry.nsh"
#######
function WriteRegQWORD
System::Call /NOUNLOAD '*(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2) i .r1'
System::Call /NOUNLOAD 'kernel32::GetSystemTime(i)i(r1)'
System::Call /NOUNLOAD 'Oleaut32::SystemTimeToVariantTime(i r1, *l .r0) i .r3'
System::Free $1
messagebox mb_ok '$0'
${registry::Write} "HKEY_CURRENT_USER\Software\_myapp" "new" "$0" "REG_QWORD" $R0
MessageBox MB_OK "registry::Write$\n$\n\
Errorlevel: [$R0]"
functionend
Vitaly
18th December 2006 12:49 UTC
Hi Red Wine,
Thank you for the example of code. I came up with something similar in the meantime, just passing REG_BINARY instead, as I’m not sure that QWORD will be read fine on any OS. Anyways, the result on Windows XP in both scenarios is the same, ending up with 9 bytes in the registry instead of 8. Any idea why that happens?
Red Wine
18th December 2006 13:06 UTC
Passing the $0 from your sample is 8 bytes for me (XP os)
demiller9
18th December 2006 14:07 UTC
I believe that REG_BINARY types have a byte count of the actual data as the first byte, giving you 9 for 8, 33 for 32, etc.
Vitaly
18th December 2006 14:19 UTC
It writes 9 bytes regardless of whether i use type REG_QWORD or REG_BINARY, which leaves the question why and how, or better question - for an application reading it as REG_BINARY how to get the actual data then? Is there something wrong with the code where i'm getting DATE first?
Vitaly
18th December 2006 14:29 UTC
I think i got it what's wrong. The 8-byte that i'm getting goes into the registry as is, i.e. ::Write converts it into text presentation, so instead of Hex form we're getting a decimal-form text string is there :))) and that string is 9 bytes, natirally. Is there a way to pre-process such decimal string so that it is a hex number?
Cannot get the right result with IntFmt yet, perhaps it cannot handle 64-bit numbers properly. What's the alternative then?
Red Wine
18th December 2006 15:59 UTC
I think the solution is in the forum as always :-)
http://forums.winamp.com/showthread....hreadid=224032
Vitaly
18th December 2006 16:16 UTC
Yes, thank you. But i just finally got it working myself, though the code does look a bit overhead:
System::Call /NOUNLOAD '*(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2) i .r1'
System::Call /NOUNLOAD 'kernel32::GetSystemTime(i)i(r1)'
System::Call /NOUNLOAD '*(&i1,&i1,&i1,&i1,&i1,&i1,&i1,&i1) i .r2'
System::Call /NOUNLOAD 'Oleaut32::SystemTimeToVariantTime(i r1, i r2) i .r3'
System::Call /NOUNLOAD '*$2(&i1,&i1,&i1,&i1,&i1,&i1,&i1,&i1)i(.r2,.r3,.r4,.r5,.r6,.r7,.r8,.r9)'
System::Free $1
System::Free $2
IntFmt $R0 "%02x" $2
IntFmt $R1 "%02x" $3
IntFmt $R2 "%02x" $4
IntFmt $R3 "%02x" $5
IntFmt $R4 "%02x" $6
IntFmt $R5 "%02x" $7
IntFmt $R6 "%02x" $8
IntFmt $R7 "%02x" $9
StrCpy $0 $R0$R1$R2$R3$R4$R5$R6$R7
${registry::Write} "HKLM\...bla-bla" "Validator" "$0" "REG_BINARY" $1
:)
demiller9
18th December 2006 19:17 UTC
You could avoid using the last StrCpy and some of the variables ($R0 to $R7) by doing it like this:
IntFmt $0 "%02x" $2
IntFmt $0 "$0%02x" $3
IntFmt $0 "$0%02x" $4
IntFmt $0 "$0%02x" $5
IntFmt $0 "$0%02x" $6
IntFmt $0 "$0%02x" $7
IntFmt $0 "$0%02x" $8
IntFmt $0 "$0%02x" $9
Vitaly
19th December 2006 14:05 UTC
yep, you are right, thank you demiller9!