Author Topic: Registry and x64 - how to go  (Read 5332 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 1058
  • User-Rate: +30/-4
  • Gender: Male
    • it-berater
« Last Edit: December 12, 2009, 10:14:29 AM by Theo Gottwald »

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 1058
  • User-Rate: +30/-4
  • Gender: Male
    • it-berater
Re: Registry and x64 - how to go
« Reply #1 on: December 13, 2009, 08:10:34 AM »
Here is an Code-Example in Powerbasic, how to read the 64bit Registry from WOW64 (32 bit PB Program).

Code: [Select]
FUNCTION X_FJ(BYVAL T01 AS STRING,BYREF T02 AS STRING,BYREF T03 AS DWORD) AS LONG
REGISTER T04 AS DWORD
LOCAL T09 AS STRING
T04=1:T01=TRIM$(T01,ANY" []\")
T09=UCASE$(EXTRACT$(T01,"\")):T02=REMAIN$(T01,"\")
SELECT CASE AS CONST$ T09
    CASE "HKEY_LOCAL_MACHINE":T03=%HKLM
    CASE "HKEY_CURRENT_USER":T03=%HKCU
    CASE "HKEY_CLASSES_ROOT":T03=%HKCR
    CASE "HKEY_USERS":T03=%HKU
    CASE "HKEY_PERFORMANCE_DATA":T03=%HKEY_PERFORMANCE_DATA
    CASE "HKEY_CURRENT_CONFIG":T03=%HKCC
    CASE "HKEY_DYN_DATA":T03=%HKDD
    CASE "HKEY_PERFORMANCE_NLSTEXT":T03=%HKEY_PERFORMANCE_NLSTEXT
    CASE "HKEY_PERFORMANCE_TEXT":T03=%HKEY_PERFORMANCE_TEXT
    CASE ELSE
      T03=%HKLM:T04=0
    END SELECT
enx:
FUNCTION=T04
END FUNCTION


' T01 - (in) String "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows" - wie aus Regedit
' T02 - (in) String "Uninstall"
' T03 - (out) Dword Type
' T04 - (out) String Value
FUNCTION X_FI64(BYVAL T01 AS STRING,BYVAL T02 AS STRING,BYREF T03 AS DWORD,BYREF T04 AS STRING) AS LONG
LOCAL T05 AS ASCIIZ*%X_FI64_MAX
LOCAL T06,T07,T08 AS DWORD,T09 AS STRING
LOCAL hKey as DWORD

T06=%X_FI64_MAX:X_FJ(T01,T09,T07)
IF RegOpenKeyEx(T07,BYVAL STRPTR(T09), 0, %KEY_READ [b]OR %KEY_WOW64_64KEY[/b], hKey) <> %ERROR_SUCCESS THEN T08=0:goto enx

T08=RegQueryValueEx(hKey,BYVAL STRPTR(T02),0,%RRF_RT_ANY,T05,T06)
IF (T08=%ERROR_SUCCESS) THEN T04=T05 ELSE T04="":T03=0

enx:
FUNCTION=T08
END FUNCTION