Archive: ReadRegStr on 64 bit WinXP


ReadRegStr on 64 bit WinXP
I have an installer that I need to run on both the 32 bit and 64 versions of windows. Everything seems to work great except that the ReadRegStr doesn't seem to return anything under the 64 bit version.

Here is the code


ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\4F1E2E1CD3D64DA40A02AE386949B0F8\InstallProperties" "DisplayName"


I know this registry entry exist and is a string. It returns a value fine under the 32 bit version but not under the 64 bit version.

What am I missing or is this command just not compatible with the 64bit version? If compatability is and issue is there another option for checking a registry entry?

I just tried a simpler entry and it returned it fine. Pulling hair out why it wouldn't like the other...


OK here is the problem. Since the NSIS installer compiles as a 32 bit app, the 64bit OS directs all interaction to a special portion of the registry.

There appears to be a special 32 bit bit fork in the registry located at

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node

So when I run the ReadRegStr command it appears to only be able to access the entries under this fork in the registry.

But I need to get the info from the real registry. Anyone?

You can write a simple 64-bit executable that'd read this registry key, and execute it from the installer. You can also use the System plug-in to manually read the registry, using the KEY_WOW64_64KEY flag (0x100) when creating the key.

The wiki contains an example of reading the registry with the System plug-in. It's a bit more complicated than what you need, as it reads REG_MULTI_SZ, but the general idea is there.


Thanks for the reply (sorry for the delay, I have been away). The example appears to be for a 32 bit system. I am sure there is something there that I need to see but I am not seeing it. You mention a KEY_WOW64_64KEY flag but I am not sure were to implement this key.


It's a flag for RegOpenKeyEx. You pass it in the samDesired parameter along with KEY_QUERY_VALUE and friends.


Hi,

I'm having the same problem. I passed KEY_WOW64_64KEY but I'm still getting the values on the 32 bit registry

Can you please help?

Best Regards,
Gustavo Guerra


Hi,

i can't manage to get registry-values on 64bit, too.

I'm testing on Windows Vista x64.

Maybe someone can help me out?

This is my code:


var ROOT_KEY
var SUB_KEY
var VALUE

!define RegOpenKeyEx "Advapi32::RegOpenKeyEx(i, t, i, i, *i) i"
!define RegQueryValueEx "Advapi32::RegQueryValueEx(i, t, i, *i, i, *i) i"

!define KEY_QUERY_VALUE 0x0001
!define KEY_ENUMERATE_SUB_KEYS 0x0008
!define KEY_WOW64_64KEY 0x100
!define REG_SZ 1

Function ReadReg64
Pop $R2
Pop $R1
Pop $R0
StrCpy $ROOT_KEY $R0
StrCpy $SUB_KEY $R1
StrCpy $VALUE $R2


StrCpy $0 ""
StrCpy $1 ""
StrCpy $2 ""
StrCpy $3 ""

SetPluginUnload alwaysoff

System::Call "${RegOpenKeyEx}($ROOT_KEY, '$SUB_KEY', \
0, ${KEY_QUERY_VALUE}|${KEY_WOW64_64KEY}, .r0) .r3"

MessageBox MB_OK "Result of RegOpenKeyEx: $3"

System::Alloc 4096
Pop $1

System::Call "${RegQueryValueEx}(r0, '$VALUE', 0, ${REG_SZ} , r1, 4096) .r3"

MessageBox MB_OK "Result of RegQueryValueEx: $3"

MessageBox MB_OK "Value: $1"

System::Free $1

FunctionEnd


As "Result of RegOpenKeyEx i always get 0 and as "Result of RegQueryValueEx" 0, too, which means, that there were no errors. But when i try to show the value, i see the adress of $1, not the correct value of my reg-key.

Testing it on Windows 2000 x86 (without the KEY_WOW64_64KEY flag) brought the same results.

Cheers,
Hütte

$1 is a pointer to a string, you would have to "extract" it with a system struct call...but...things have changed since this thread was started, NSIS now has SetRegView


SetRegView! That's cool. Thank you!

I still use NSIS 2.27 because i don't want to dismiss HM NIS Edit. But now it's time for an update.


HM Nis edit works with every version after that, it just might be missing some of the new keywords, but there is a updated syntax file if you search around