-
November 3rd, 2020, 03:14 AM
#1
Registry access in Windows 7
I'm working on a program which uses RegOpenKey() and RegQueryValueEx() to access a particular registry key. Usually the key gets accessed like this:-
Code:
HKEY_CURRENT_USER\Software\Jack
but I've just noticed that if I change it to this, it fails on Windows 7:-
Code:
HKEY_CURRENT_USER\SOFTWARE\Jack
Although it seems to still work in Win8.1 - so is registry access case-sensitive in Win7? I'm just curious because that'd be quite unusual for Windows.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
November 3rd, 2020, 03:54 AM
#2
Re: Registry access in Windows 7
I believe the registry has always been case sensitive.
-
November 3rd, 2020, 05:05 AM
#3
Re: Registry access in Windows 7
Thanks Arjay - after a bit more experimenting I've realised there's an extra element to this... it only seems to happen if I run a 32-bit app on Win64. Initially, the app tries to open its regkey like this:-
Code:
RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\Jack", 0, KEY_READ, &key);
For a 32-bit app on Win32, that call seems to succeed - regardless of upper case / mixed case etc. But for a 32-bit app on a Win64, that call only succeeds if the case is correct. And even then, it only succeeds for HKEY_CURRENT_USER. If we try to open a key under HKEY_LOCAL_MACHINE, we need to change the above call to this:-
Code:
RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Jack", 0, KEY_READ, &key);
But regardless of case, the above call always fails (even if the key exists) and the program then tries again, like this:-
Code:
RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Jack", 0, KEY_READ | KEY_WOW64_32KEY, &key);
But the 'KEY_WOW64_32KEY' option seems to always fail too (again, regardless of upper case / mixed case etc). So I'm guessing the 2nd option isn't quite right if a 32-bit app needs to open a HKEY_LOCAL_MACHINE key on Win64
Or does HKEY_LOCAL_MACHINE have stricter access permissions maybe??
Last edited by John E; November 3rd, 2020 at 05:59 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
November 3rd, 2020, 09:28 PM
#4
Re: Registry access in Windows 7
There is some msdn documentation on how the registry stores values fir 32bit apps running on 64bit windows. Sorry I don't have a direct link.
-
November 4th, 2020, 02:24 AM
#5
Re: Registry access in Windows 7
Originally Posted by John E
I'm working on a program which uses RegOpenKey() and RegQueryValueEx().....
... so is registry access case-sensitive in Win7? I'm just curious because that'd be quite unusual for Windows.
According to docs:
Parameters
hKey
A handle to an open registry key. This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:
HKEY_CLASSES_ROOT HKEY_CURRENT_CONFIG HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS
lpSubKey
The name of the registry subkey to be opened.
Key names are not case sensitive.
So both:
Code:
RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\Jack",
and
Code:
RegOpenKeyExA (HKEY_CURRENT_USER, "SOFTWARE\\Jack",
should you give the same result.
BTW, what error do you get?
Victor Nijegorodov
-
November 4th, 2020, 07:34 AM
#6
Re: Registry access in Windows 7
RegOpenKeyExA() is returning a value of 2 (ERROR_FILE_NOT_FOUND)
Originally Posted by John E
it only seems to happen if I run a 32-bit app on Win64
This probably won't sound right but here's what seems to be happening...
On 64-bit Windows, if a 32-bit app tries to query HKEY_LOCAL_MACHINE\SOFTWARE, Windows seems to assume that the required key will be found under WOW6432Node. AFAICT the other nodes in SOFTWARE simply don't get searched - they only get searched if the requesting app is 64-bit. What's strange is that HKEY_CURRENT_USER\Software also has a node called WOW6432Node - but that one only gets used for Microsoft software, so the same assumption doesn't seem to apply there - i.e. everything under HKEY_CURRENT_USER\Software will get searched.
Last edited by John E; November 4th, 2020 at 10:06 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
November 7th, 2020, 02:59 PM
#7
Re: Registry access in Windows 7
Originally Posted by John E
RegOpenKeyExA() is returning a value of 2 (ERROR_FILE_NOT_FOUND)
This probably won't sound right but here's what seems to be happening...
On 64-bit Windows, if a 32-bit app tries to query HKEY_LOCAL_MACHINE\SOFTWARE, Windows seems to assume that the required key will be found under WOW6432Node. AFAICT the other nodes in SOFTWARE simply don't get searched - they only get searched if the requesting app is 64-bit. What's strange is that HKEY_CURRENT_USER\Software also has a node called WOW6432Node - but that one only gets used for Microsoft software, so the same assumption doesn't seem to apply there - i.e. everything under HKEY_CURRENT_USER\Software will get searched.
See post #4
-
November 8th, 2020, 08:42 AM
#8
Re: Registry access in Windows 7
Originally Posted by Arjay
See post #4
Thanks Arjay - I came across this item which mentions an extra parameter called KEY_WOW64_64KEY. It can be used by a 32-bit app to force Windows to examine 64-bit keys when running on a 64-bit OS. AFAICT there's no detriment when the app gets run in Win32.
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|