is it possible? i sent my friend an app that works fine on my 32bit machine, but on his 64bit it errors reading the key
using this
GetString proc lpszKey:DWORD,lpszValueName:DWORD,lpszBuffer:DWORD
LOCAL dwStrLength:DWORD
LOCAL phkResult :DWORD
LOCAL RType:DWORD
LOCAL lpcbData :DWORD
local szbuf[256]:BYTE
invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE,lpszKey,0,KEY_READ,addr phkResult
.if eax==ERROR_SUCCESS
mov RType,REG_SZ
mov lpcbData, 250
invoke RegQueryValueEx,phkResult,lpszValueName,NULL, addr RType, lpszBuffer,addr lpcbData
.if eax==ERROR_SUCCESS
.else
invoke lstrcat,lpszBuffer,CTEXT("RegKey Does Not Exist")
.endif
.else
invoke lstrcat,lpszBuffer,CTEXT("Error Opening RegKey!")
.endif
invoke RegCloseKey, phkResult
ret
GetString endp
See if this page helps at all :
http://msdn.microsoft.com/en-us/library/ms724072(VS.85).aspx
You might also need admin access when using HKEY_LOCAL_MACHINE on vista/win7
im using a manifest.xml to prompt for admin access and still nada
i think the registry gets virtualized - you have to access it through the a "wow64" hive (or something like that)
so, HKEY_LOCAL_MACHINE becomes wow64\HKEY_LOCAL_MACHINE
i had to do it once - that worked for what i was doing because i was only reading the registry
you may have to jump through hoops if you want to write to it and have it stick after a re-boot
actually, its done using a flag in the access rights..
KEY_WOW64_32KEY (0x0200)
Indicates that an application on 64-bit Windows should operate on the 32-bit registry view. For more information, see Accessing an Alternate Registry View.
This flag must be combined using the OR operator with the other flags in this table that either query or access registry values.
Windows 2000: This flag is not supported.
KEY_WOW64_64KEY (0x0100)
Indicates that an application on 64-bit Windows should operate on the 64-bit registry view. For more information, see Accessing an Alternate Registry View.
This flag must be combined using the OR operator with the other flags in this table that either query or access registry values.
Windows 2000: This flag is not supported.
source : http://msdn.microsoft.com/en-us/library/ms724878%28VS.85%29.aspx
testing on win7 home premium 64bit I tried using the samDesired parameter of KEY_WOW64_64KEY
heres the code so you can get a good example of what im trying to achieve
.386
.model flat, stdcall
option casemap:none
GetString proto :DWORD,:DWORD ,:DWORD
CTEXT MACRO y:VARARG
LOCAL sym, dummy
dummy EQU $;; MASM error fix
CONST segment
IFIDNI <y>,<>
sym db 0
ELSE
sym db y,0
ENDIF
CONST ends
EXITM <OFFSET sym>
ENDM
include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
includelib user32.lib
includelib kernel32.lib
includelib advapi32.lib
.data
szKey db "SOFTWARE\Microsoft\Windows NT\CurrentVersion",0
.data?
buffstuff db 1024 dup(?)
.code
start:
invoke GetString,addr szKey,CTEXT("ProductName"),addr buffstuff
invoke MessageBox, NULL,addr buffstuff,CTEXT('Result'), MB_OK
invoke ExitProcess,NULL
GetString proc lpszKey:DWORD,lpszValueName:DWORD,lpszBuffer:DWORD
LOCAL dwStrLength:DWORD
LOCAL phkResult :DWORD
LOCAL RType:DWORD
LOCAL lpcbData :DWORD
local szbuf[256]:BYTE
invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE,lpszKey,0,KEY_READ or KEY_WOW64_64KEY ,addr phkResult
.if eax==ERROR_SUCCESS
mov RType,REG_SZ
mov lpcbData, 250
invoke RegQueryValueEx,phkResult,lpszValueName,NULL, addr RType, lpszBuffer,addr lpcbData
.if eax==ERROR_SUCCESS
.else
invoke lstrcat,lpszBuffer,CTEXT("RegKey Does Not Exist")
.endif
.else
invoke lstrcat,lpszBuffer,CTEXT("Error Opening RegKey!")
.endif
invoke RegCloseKey, phkResult
ret
GetString endp
end start
Chilly, in response to http://www.masm32.com/board/index.php?topic=13209.0
here is the code I used for that
EnumExtensions32 proc uses ebx edi esi
LOCAL FileExt[50]:BYTE
LOCAL lpcBuffer:DWORD
LOCAL FTime:FILETIME
LOCAL hKey:DWORD
invoke RegOpenKeyEx, HKEY_CLASSES_ROOT, NULL, NULL,KEY_ENUMERATE_SUB_KEYS or KEY_WOW64_32KEY, addr hKey
xor ebx, ebx
inc ebx ; Skip * key
xor edi, edi
GetNextExtension:
lea esi, FileExt
push NULL
push 50
push esi
call memfill
mov lpcBuffer, 50
; Enumerate each key in HCR
lea eax, FTime
push eax
push NULL
push NULL
push NULL
lea ecx, lpcBuffer
push ecx
push esi
push ebx
push hKey
call RegEnumKeyEx
cmp eax, ERROR_NO_MORE_ITEMS
je EnumDone
; Get only extensions
mov al, byte ptr [esi]
cmp al, '.'
;jne NextExt
jne EnumDone
; Make sure not a .??_ file
mov al, byte ptr [esi + 3]
cmp al, '_'
je NextExt
NextExt:
inc ebx
jmp GetNextExtension
EnumDone:
lea esi, FileExt
push NULL
push 50
push esi
call memfill
push esi
push ebx
call dwtoa
push 0
push offset szMainCaption1
push esi
push 0
call MessageBox
ret
EnumExtensions32 endp
I do a lot of Registry access with many of my programs, I will take a closer look at your code in a bit to see if I notice anything
RegOpenKeyEx seems to be failing
if im doing formatmessage right it seems to be returning "access is denied" even though app is running as admin
change my .else to this:
.else
invoke ShowErrorMessage,0,eax
invoke lstrcat,lpszBuffer,CTEXT("Error Opening RegKey!")
.endif
ShowErrorMessage hWnd,dwError
local lpBuffer:DWORD
lea eax,[lpBuffer]
invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0
invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK
invoke LocalFree,[lpBuffer]
ret
ShowErrorMessage endp
it may be the stack alignment - there is concurrently another thread on that issue
whats the link to the other thread
http://www.masm32.com/board/index.php?topic=13186.msg102596#msg102596
The stack alignment issue in the other thread pertains to 64-bit programs.
Quote from: ChillyWilly on January 23, 2010, 09:15:19 PM
testing on win7 home premium 64bit I tried using the samDesired parameter of KEY_WOW64_64KEY
heres the code so you can get a good example of what im trying to achieve
this is working just fine for me if i remove the KEY_WOW64_64KEY flag...
>this is working just fine for me if i remove the KEY_WOW64_64KEY flag
Same here, even without admin.
which version of windows are you guys running?
Win7 RC x64
ChillyWilly .. I have the same problem here. If I use KEY_WOW64_64KEY I get an error 5 = "access denied" and if I dont use it, I can open the key but I cant read the value (error 2 = DONT_FOUND). I tried running as an Administrator and Disabling UAC with no sucess. Im on Windows 7 x64.
Let me know if you found what the problem is and the solution...
yea thats where im at too
not sure how its working on sinsi if its not working on us
It works for me if I remove the KEY_WOW64_64KEY. Windows 7 Pro x64 retail.
what about reading the digitalproductid key?
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
DigitalProductId
Quotewhat about reading the digitalproductid key?
Not without modifying your code quite a bit. I can read it with PowerShell since I already had a script to do that. Good for retrieving the Windows Product Key.
DigitalProductId is REG_BINARY, not REG_SZ, so yeah lots of modification to your code.
ok ill try to whip something up tomorrow and test it and ill post back if its not working
I have problems reading the "DigitalProductId"... the code works on Windows XP SP3 (x86) and Windows Vista SP2 (x86)... so it doesnt work in 64 bits Windows. Still dunno why.
I tried opening the key with: KEY_QUERY_VALUE, KEY_READ and KEY_ALL_ACCESS and reading the "DigitalPRoductId" with REG_BINARY and REG_DWORD and as I said it works ok in 32 bits but fails in 64bits:
If I use KEY_WOW64_64KEY to open the key I get an error 5 = "access denied" and if I dont use it, I can open the key but I cant read the value "DigitalProductId" (error 2 = DONT_FOUND).
i would be curious to see the results of the last attachment in this post...
http://www.masm32.com/board/index.php?topic=11963.msg90835#msg90835
if you browse through that thread, there are posted results from 64-bit OS's
DednDave OS Info Dump Ver 2.03
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"ProductName"="Windows 7 Ultimate"
"CurrentVersion"="6.1"
"CurrentBuildNumber"="7600"
"SubVersionNumber"=(Value not found)
"CSDVersion"=(Value not found)
"BuildLab"="7600.win7_rtm.090713-1255"
"ProductId"=(Value not found)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center]
"Ident"="6.0"
OSVERSIONINFOEX Structure:
Version.Build: 6.1.7600
Platform ID: Win32 on Windows NT
CSD Version:
Service Pack Version: 0.0
Suite Mask: 0000000100000000
Product Type: Windows 2000 Pro/XP/Vista Workstation
Press any key to exit
Im seeing right now the ProductId value in Regedit... :eek
Im reading a lot on info online and in all examples they use KEY_WOW64_64KEY with success... why we get the "permission denied" error? ...
that's what i mean - lol
i didn't do anything special in that program - i am pretty sure the source code is there :bg
All people with 64 bits posted: "ProductId"=(Value not found)
You need to use KEY_WOW64_64KEY when open the key... but, at least here, I get the error code = 5 (access denied)
maybe this article will help, even though it applies to installing AVG - the cure might be the same
http://www.copyrunstart.net/quick-fix-avg-antivirus-80-error-message-error-action-failed-for-registry-key/
DednDave OS Info Dump Ver 2.03
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]
"ProductName"="Windows 7 Home Premium"
"CurrentVersion"="6.1"
"CurrentBuildNumber"="7600"
"SubVersionNumber"=(Value not found)
"CSDVersion"=(Value not found)
"BuildLab"="7600.win7_rtm.090713-1255"
"ProductId"=(Value not found)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center]
"Ident"="6.0"
OSVERSIONINFOEX Structure:
Version.Build: 6.1.7600
Platform ID: Win32 on Windows NT
CSD Version:
Service Pack Version: 0.0
Suite Mask: 0000001100000000
Product Type: Windows 2000 Pro/XP/Vista Workstation
Press any key to exit
well - i think i wrote that code about the same time the win 7 beta came out
so - things have obviously changed a bit - lol
for my purposes, i only needed the product ID to differentiate some of the oddball XP's (like XP gold, XP gamers edition, etc)
at the time, i was looking for a way to seperate XP media center editions, but i found that "Ident" key that you see
any success?
how come I cant read this registry value?
the other string values in that key can be read :'(
.386
.model flat, stdcall
option casemap:none
GetString proto :DWORD,:DWORD ,:DWORD
CTEXT MACRO y:VARARG
LOCAL sym, dummy
dummy EQU $;; MASM error fix
CONST segment
IFIDNI <y>,<>
sym db 0
ELSE
sym db y,0
ENDIF
CONST ends
EXITM <OFFSET sym>
ENDM
include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
includelib user32.lib
includelib kernel32.lib
includelib advapi32.lib
.data
.data?
buffstuff db 1024 dup(?)
.code
start:
invoke GetString,CTEXT("SOFTWARE\Microsoft\Windows NT\CurrentVersion"),CTEXT("DigitalProductId"),addr buffstuff
invoke MessageBox, NULL,addr buffstuff,CTEXT('Result'), MB_OK
invoke ExitProcess,NULL
ShowErrorMessage proc hWnd,dwError
local lpBuffer:DWORD
lea eax,[lpBuffer]
invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0
invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK
invoke LocalFree,[lpBuffer]
ret
ShowErrorMessage endp
GetString proc lpszKey:DWORD,lpszValueName:DWORD,lpszBuffer:DWORD
LOCAL dwStrLength:DWORD
LOCAL phkResult :DWORD
LOCAL RType:DWORD
LOCAL lpcbData :DWORD
local szbuf[256]:BYTE
invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE,lpszKey,0,KEY_QUERY_VALUE ,addr phkResult
.if eax==ERROR_SUCCESS
mov RType,REG_BINARY
mov lpcbData, 250
invoke RegQueryValueEx,phkResult,lpszValueName,NULL, addr RType, lpszBuffer,addr lpcbData
.if eax==ERROR_SUCCESS
.else
invoke lstrcat,lpszBuffer,CTEXT("RegKey Does Not Exist")
.endif
.else
invoke ShowErrorMessage,0,eax
invoke lstrcat,lpszBuffer,CTEXT("Error Opening RegKey!")
.endif
invoke RegCloseKey, phkResult
ret
GetString endp
end start
noone knows? theres gotta be someone here with a 64bit cpu that better at coding than me :dazzled:
It shows the value fine here... it shows the first hex value of that binary reg value on my Win7 32bit is a4, after a4 are a few NULLs so that is the ONLY character messages box shows.... You are going to have to parse that value and get what is after the nulls... it is REG_BINARY NOT REG_SZ which to me means the there are going to be NULLs in the value..
Is the format the same across os's? don't know... here is how mine starts:
A4 00 00 00 03 00 00 00 00 DigitalProductId HERE
does the 3 mean there are 3 nulls before the DigitalProductId don't know, you are going to have to figure out how to parse the buffer to grab the DigitalProductId
its a bug in the windows.inc
correct:
KEY_WOW64_32KEY equ 0200h
KEY_WOW64_64KEY equ 0100h
KEY_WOW64_RES equ 0300h
wrong:
KEY_WOW64_32KEY equ 0200
KEY_WOW64_64KEY equ 0100
KEY_WOW64_RES equ 0300
nice catch, diablo
should post in the masm32 project forum, windows.inc thread