AutoHotkey Community

It is currently May 26th, 2012, 1:37 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: September 25th, 2007, 10:15 am 
Offline

Joined: September 18th, 2007, 7:01 pm
Posts: 5
x64 applications write to the registry here:
HKEY_LOCAL_MACHINE\SOFTWARE

x32 applications on x64 are intercepted by the system and write here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node

This is transparent to the user.
(description from microsoft http://support.microsoft.com/kb/896459)

When x32 apps read from the registry the read from here:
HKEY_LOCAL_MACHINE\SOFTWARE
but the system again intercepts and gets the values from:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node

What happens if a x32 application (like an autohotkey script .ahk or compiled) tries to read from a key that belongs to a x64 application?
That the call is intercepted by the system and you get an empty result, because it looks for it on HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node

So, there is no way to read keys from HKEY_LOCAL_MACHINE\SOFTWARE with a x32 application if they were written by a x64 application.


p.e:
Maya2008 32 installed on Windows XP 32
Code:
RegRead, dirmaya, HKLM, Software\Autodesk\Maya\2008\Setup\InstallPath,MAYA_INSTALL_LOCATION
msgbox, %dirmaya%
Result: C:\Program Files\3D\Maya2008

Maya2008 64 installed on Windows XP 64
The same RegRead code
Result:
Nothing.....

Manually create in the registry a duplicate on HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node:
Code:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Autodesk\Maya\2008\Setup\InstallPath]
"MAYA_INSTALL_LOCATION"="c:\\Program Files\\3D\\Maya2008_fake_path"

And again the same code
Result: C:\Program Files\3D\Maya2008_fake_path


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2007, 1:08 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Sorry for the late reply. Currently, I think the only way to access entries that exist only in the 64-bit section of the registry is by calling a function like RegOpenKeyEx() via DllCall and passing to it the KEY_WOW64_64KEY flag.

For details, see:
http://msdn2.microsoft.com/en-gb/library/aa384129.aspx
http://msdn2.microsoft.com/en-us/library/ms724878.aspx

The current behavior is an intentional limitation imposed by Microsoft on 32-bit apps running in a 64-bit environment. Therefore, I've moved this to Wish List in the hope that a future version will provide a built-in means to access the 64-bit-only areas of the registry.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 19th, 2008, 6:15 am 
Offline

Joined: August 4th, 2007, 10:39 pm
Posts: 44
I know this thread is quite old, but I'm running into the same issue with needing to read a registry entry made by a 64 bit application using AHK. I'm not familiar with how to use the dllcall with Advapi32.dll. I would appreciate any help with syntax as I'm sure I'm doing it wrong. Below is a test I'm trying to run. I created a key under SYSTEM just to test, but the message box is still returning a blank. I can read the value just fine with regread.

Code:
myhKey:= HKEY_LOCAL_MACHINE
sKeyName:= SYSTEM
sValueName:= InstallLocation

DllCall("Advapi32.dll\RegOpenKeyEx", myhKey, sKeyName, 0, KEY_QUERY_VALUE, hKey)
DllCall("Advapi32.dll\QueryValueEx", hKey, sValueName, vValue)
MsgBox, %vValue%

_________________
Regards,
Dave B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2008, 6:47 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
There are a number of problems with your code:
  • HKEY_LOCAL_MACHINE and KEY_QUERY_VALUE are constants defined in the Windows header files. You must use the corresponding numeric values.
  • Quote marks are required when assigning a literal string using :=. If SYSTEM has not been assigned a value, sKeyName:=SYSTEM will assign sKeyName a blank value.
  • DllCall sets ErrorLevel to -2 or -4. -2 because you've omitted the arg types, and -4 because RegOpenKeyEx and QueryValueEx do not exist. Use RegOpenKeyExA and RegQueryValueExA.
  • Once you specify the correct arg types, you'll also need to initialize vValue using VarSetCapacity.
Try the following:
Code:
HKEY_LOCAL_MACHINE := 0x80000002
KEY_QUERY_VALUE := 0x1

myhKey := HKEY_LOCAL_MACHINE
sKeyName := "SYSTEM"            ; Note quote marks with :=
sValueName = InstallLocation    ; Note NO quote marks with =

DllCall("Advapi32.dll\RegOpenKeyExA", "uint", myhKey, "str", sKeyName, "uint", 0, "uint", KEY_QUERY_VALUE, "uint*", hKey)
MsgBox % hKey " (ErrorLevel: " ErrorLevel ")"
VarSetCapacity(vValue, vValueSize:=1024)    ; vValueSize := Arbitrary maximum length.
DllCall("Advapi32.dll\RegQueryValueExA", "uint", hKey, "str", sValueName, "uint", 0, "uint", 0, "str", vValue, "uint*", vValueSize)
MsgBox % vValue " (ErrorLevel: " ErrorLevel ")"
(Tested only on 32-bit Vista.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Works perfect
PostPosted: December 4th, 2008, 5:15 pm 
Offline

Joined: August 12th, 2007, 3:49 am
Posts: 12
Thanks for the pointers everyone - I also needed a fix for this and the details in this post helped perfect.
Just wanted to paste in a working sample that combines Chris and Lexikos notes above:

Code:
HKEY_LOCAL_MACHINE := 0x80000002
KEY_WOW64_64KEY := 0x0100
KEY_QUERY_VALUE := 0x1

myhKey := HKEY_LOCAL_MACHINE
sKeyName := "SOFTWARE\Company\Product"
sValueName := "myregvaluename"

DllCall("Advapi32.dll\RegOpenKeyExA", "uint", myhKey, "str", sKeyName, "uint", 0, "uint", KEY_QUERY_VALUE+KEY_WOW64_64KEY, "uint*", hKey)
MsgBox % hKey " (ErrorLevel: " ErrorLevel ")"
VarSetCapacity(vValue, vValueSize:=1024)
DllCall("Advapi32.dll\RegQueryValueExA", "uint", hKey, "str", sValueName, "uint", 0, "uint", 0, "str", vValue, "uint*", vValueSize)
MsgBox % vValue " (ErrorLevel: " ErrorLevel ")"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2008, 1:01 am 
Offline

Joined: August 4th, 2007, 10:39 pm
Posts: 44
Thanks a TON guys. That working example is perfect. I'm not that knowledgeable in using dllcall (or most of AHK anyway!). I appreciate all the help. Too bad I wasn't smart enough to figure out the syntax until the last 2 posts :)

_________________
Regards,
Dave B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 3:48 pm 
Offline

Joined: August 12th, 2007, 3:49 am
Posts: 12
Posted full RegRead64() and RegWrite64() functions on this page:

http://www.autohotkey.com/forum/viewtopic.php?p=241769


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group