registry in windows 7

Blitz3D Forums/Blitz3D Programming/registry in windows 7

Jp1985(Posted 2012) [#1]
Hi,
I want to be able to read the keys from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\GameUX and I am running in windows 7 x64. I have found multiple ways of doing this, running batch files, win api, external decal but none of them actually return the keys.
For example running the batch file:

C:\WINDOWS\System32\reg.exe query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\GameUX >> z:\test3.txt

Outputs all the keys in the registry to test3.txt. Perfect.
However if I run this file from my blitz3d program it only finds a single key(MachineSettings) and not the ones I need (like Games). The same thing happens with the api, using regedit commandline and decals.

I am also running the program with admin level privileges built into its manifest and have tried running program as administrator as well.
Its as if windows doesn't want external programs to see those keys as looking in regedit shows the keys fine.

Any help you can give will be excellent as this has been bugging me for over 2 days now and has halted my project greatly.


Yue(Posted 2012) [#2]
use PhysX dll, functions.

http://blitzbasic.com/Community/posts.php?topic=90281

Last edited 2012


Jp1985(Posted 2012) [#3]
Thanks for that but the dll doesn't contain any way to query keys. I want to enumerate all the keys not just read a single value or write a single value.
The registry area I am reading from can potentially have hundreds of different valued keys in it so there is no way for me to know the exact path of each key hence I need a function that returns the values of each of the subkeys


Guy Fawkes(Posted 2012) [#4]
Did u try any other plugins they might have? They have a WIDE variety of registry API plugins


GaryV(Posted 2012) [#5]
but none of them actually return the keys.
This is because you are trying to read it from the wrong registry. 64-bit versions of Windows do not natively support 32-bit software. 64-bit versions of Windows will only run 32-bit software via emulation using WoW64. If you insist on running 32-bit software, you need to use the proper locations so the emulator can find the data you need.

You have a 64-bit OS and you are running a 32-bit EXE. If you try and write to 64-bit registry, it should be automatically written to the 32-bit registry equivalent. If you want to read that value, you need to read the 32-bit registry equivalent, you can't read it from the 64-bit registry because it was never written there.

If you have a 32-bit app, you should only be reading and writing to the 32-bit registry equivalent. Example: HKEY_LOCAL_MACHINE\Software\Wow6432Node

Also, on a 64-bit system, c:\windows\system32 is only for 64-bit stuff. 32-bit stuff will be kept in the equivalent name that includes the emulator's name: c:\windows\SysWOW64

If you go to explorer and navigate to c:\windows\SysWOW64 you will see 32-bit versions of many things that are in c:\windows\system32 If there is a regedit in c:\windows\SysWOW64, it should load your 32-bit registry entries. Otherwise you will need to use the normal registry editor and navigate to the 32-bit equivalents for each registry category.

FWIW, this is nothing new and has been like this on 64-bit versions of XP and Vista, but since those versions were hardly used, this is new to many people.

Last edited 2012


GaryV(Posted 2012) [#6]
Ps. Any DLLs distributed with a 32-bit exe and not kept in your program's directory should be placed in c:\windows\SysWOW64 so the emulator can find them. This is another "gotcha" that snags some folks. 32-bit DLLs need to go in the eumlator's system directory.

Last edited 2012


Guy Fawkes(Posted 2012) [#7]
Coolios :)


Jp1985(Posted 2012) [#8]
Thanks GaryV your a lifesaver :)

For other people looking to solve this, I used the following method to read 64bit keys:

Local temp_proc:Tprocess = CreateProcess("C:\Windows\sysnative\reg.exe QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\GameUX",1)

Running a 32-bit app on a 64-bit OS redirects system32 to SYSWOW64 automatically.
The sysnative is a virtual directory that actually points to the real system32 folder. Running the 64bit Reg with proper command line options returns 64bit registry items.

Heres my full code:
Local temp_proc:Tprocess = CreateProcess(GetEnv("WINDIR")+"\sysnative\reg.exe QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\GameUX",1)
While temp_proc.status()
	If temp_proc.pipe.ReadAvail() Print "pipe: " + temp_proc.pipe.ReadLine()
Wend

Extern "Win32"
	Function GetEnvironmentVariable(lpName$z, lpBuffer:Byte Ptr, nSize) = "GetEnvironmentVariableA@12"
End Extern

Function GetEnv$(envVar$)
		Local buff@[64]
		
		Local rtn = GetEnvironmentVariable(envVar$, buff@, buff.length)
		If rtn > buff.length
			buff@ = buff@...]
			rtn = GetEnvironmentVariable(envVar$, buff@, buff.length)
		EndIf
		
		Return String.FromBytes(buff@, rtn)
End Function


Last edited 2012

Last edited 2012


Fielder(Posted 2015) [#9]
seems that there are issues with this code (on windows 8.1 and 10)

http://www.blitzmax.com/Community/posts.php?topic=105477

any idea in how to use the standard APIs and KEY_WOW64_64KEY = 0x0100 ???