Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Registry access limitations on Windows XP 64


  • Please log in to reply
7 replies to this topic
voxel
  • Members
  • 5 posts
  • Last active: Sep 25 2007 09:45 AM
  • Joined: 18 Sep 2007
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 <!-- m -->http://support.microsoft.com/kb/896459<!-- m -->)

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
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:
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

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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:
<!-- m -->http://msdn2.microso...y/aa384129.aspx<!-- m -->
<!-- m -->http://msdn2.microso...y/ms724878.aspx<!-- m -->

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.

dbaldacchino
  • Members
  • 44 posts
  • Last active: Apr 27 2010 04:21 PM
  • Joined: 04 Aug 2007
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.

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.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
There are a number of problems with your code:
[*:2jspov9j]HKEY_LOCAL_MACHINE and KEY_QUERY_VALUE are constants defined in the Windows header files. You must use the corresponding numeric values.
[*:2jspov9j]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.
[*:2jspov9j]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.
[*:2jspov9j]Once you specify the correct arg types, you'll also need to initialize vValue using VarSetCapacity.Try the following:
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.)

tomte
  • Members
  • 12 posts
  • Last active: Aug 07 2011 09:02 PM
  • Joined: 12 Aug 2007
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:

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 ")"


dbaldacchino
  • Members
  • 44 posts
  • Last active: Apr 27 2010 04:21 PM
  • Joined: 04 Aug 2007
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.

tomte
  • Members
  • 12 posts
  • Last active: Aug 07 2011 09:02 PM
  • Joined: 12 Aug 2007
Posted full RegRead64() and RegWrite64() functions on this page:

<!-- m -->http://www.autohotke...ic.php?p=241769<!-- m -->

Aero98
  • Members
  • 112 posts
  • Last active: Mar 29 2013 03:42 PM
  • Joined: 08 Jan 2009
While it is not really the way I would like to do it, I did find a workaround. While using the following code does not tell me if an instance is an x32 or x64 instance of SQL, it does properly detectd and list all instances of SQL.



SQLcount = 	[color=#004000];Initiate blank variable[/color]
SQLTcount =	[color=#004000];Initiate blank variable[/color]

Loop, HKLM, System\Currentcontrolset\Services, 2	[color=#004000];Parses the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services registry keys[/color]
{
	ifinstring, A_LoopRegName, MSSQL	[color=#004000];If the Registry key contains MSSQL, parse it, otherwise, loop to the next key[/color]
	{
	IfNotInString, A_loopRegName, ServerADHelper	[color=#004000];Strips out the ServerADHelp keys, they are related to an instance, but not the instance its self[/color]
		{
			SQLcount = %SQLcount%%A_LoopRegName%`n		[color=#004000];Saves the returned Vaule to the current list of discovered instances[/color]
			SQLTcount += 1								[color=#004000];Incriments the number of instances counter[/color]
		}
	}
}
StringReplace, SQLcount, SQLcount, MSSQL,,All	[color=#004000];Parses the instances names into a user frinedly format[/color]
StringReplace, SQLcount, SQLcount, $,,All		[color=#004000];Parses the instances names into a user frinedly format[/color]

if SQLTcount = 1	[color=#004000];If the number of SQL instances discovered is only one[/color]
{
	RegRead, installSQL, HKLM, SOFTWARE\Microsoft\Microsoft SQL Server\ALAMODE\Setup, SQLPATH [color=#004000];Check to see if the ALAMODE instance is already installed[/color]
		if installSQL =	[color=#004000];If this entry is blank, the ALAMODE instance is not installed[/color]
		{
			MsgBox, 262192, Warning, Another instance of SQL was found on the system:`n%SQLcount%`nSQL repair will still be able to install the alamode `ninstance of SQL`; However`, it will not perform the preclean`nprocess prior to install because of possible conflicts with`nother installed versions of SQL. , 30
			If override != 1		[color=#004000];If the user did not choose to override the default safety features preventing the uninstallation of other instances of SQL[/color]
			Install = 1			[color=#004000];Set the utility to install mode instead of repair, (Uninstall/reinstall) mode[/color]
		}
}
else if SQLtCount > 1	[color=#004000];If the number of SQL instances discovered is greater than one[/color]
{
	RegRead, installSQL, HKLM, SOFTWARE\Microsoft\Microsoft SQL Server\ALAMODE\Setup, SQLPATH [color=#004000];Check to see if the ALAMODE instance is already installed[/color]
		if installSQL =	[color=#004000];If this entry is blank, the ALAMODE instance is not installed[/color]
		{
			MsgBox, 262192, Warning, Another instance of SQL was found on the system:`n%SQLcount%`nSQL repair will still be able to install the alamode `ninstance of SQL`; However`, it will not perform the preclean`nprocess prior to install because of possible conflicts with`nother installed versions of SQL. , 30
			If override != 1		[color=#004000];If the user did not choose to override the default safety features preventing the uninstallation of other instances of SQL[/color]
			Install = 1			[color=#004000];Set the utility to install mode instead of repair, (Uninstall/reinstall) mode	[/color]
		}
		else		[color=#004000];If another instance of SQL and the ALAMODE instance both exist, cannot continue. (Override command would bypass this, but will remove ALL instances of SQL)[/color]
		{
			MsgBox, 131088, Error, More than one instance of SQL has been detected on this machine:`n%SQLcount%`nThis utility is unable to automatically repair/reinstall The `na la mode instance of SQL if another instance of SQL is present. `n`nPlease contact a tech to repair SQL manually.`nThis utility will now close.
		if override != 1 [color=#004000]; Allows override option to bypass the detection of multiple instances of SQL (Will cause all other instances of SQL to be lost)[/color]
				{
			Exitapp
				}
		}
}
MsgBox, 64, No instances of SQL Detected, No instances of SQL were dected`, SQLrepair will operate normally. [color=#004000];Should only display if the above logic cannot detect ANY installed instance of SQL on the machine, x32 or x64.[/color]
Exitapp


(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination.