[RESOLVED] Read WindowsId from Win7 (64-bit) registry
I have a problem reading the product ID value in Windows 7 64 bit. The program reads the value with out a problem on WinXP platform, but when I switch to Win7 I just get "...". Starting the application with the "Run as Administrator" makes no difference. The ProductId string would be used to bind the program to one specific Windows Installation.
I would like to apologize if this problem was already addressed here on forums, but after a thorough search I just couldn't find anything close to what I need.
I thank you in advance.
The code used is as follows:
Code:
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Const REG_SZ = 1
Private Const LOCALMACHINE = &H80000002 ' This is really HKEY_LOCAL_MACHINE
Private Sub cmdReadId_Click()
Dim nBufferKey As Long
Dim nBufferName As String
nBufferName = Space(256)
RegOpenKey LOCALMACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", nBufferKey
RegQueryValueEx nBufferKey, "ProductId", 0, REG_SZ, nBufferName, Len(nBufferName)
Form1.caption = nBufferName
End Sub