Results 1 to 7 of 7

Thread: [RESOLVED] Read WindowsId from Win7 (64-bit) registry

  1. #1

    Thread Starter
    Junior Member asasino's Avatar
    Join Date
    Nov 2007
    Posts
    24

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Read WindowsId from Win7 (64-bit) registry

    Perhaps you haven't heard about WOW64 registry redirection.

    The attachment shows how to get the information you want (and more).
    Attached Files Attached Files

  3. #3

    Thread Starter
    Junior Member asasino's Avatar
    Join Date
    Nov 2007
    Posts
    24

    Re: Read WindowsId from Win7 (64-bit) registry

    Thank you! Tried it out last night on Win7 64-bit and works perfectly. Was just the thing I was lookin' for. Thank you again.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Read WindowsId from Win7 (64-bit) registry

    You're quite welcome.

  5. #5
    New Member
    Join Date
    Nov 2013
    Posts
    3

    Re: [RESOLVED] Read WindowsId from Win7 (64-bit) registry

    Quote Originally Posted by dilettante View Post
    You're quite welcome.
    please add regsetvalueex into your module for x64 system if possible

    thanks

  6. #6
    ....
    Last edited by chejunkie; Jul 22nd, 2021 at 08:51 PM.

  7. #7

    Re: Read WindowsId from Win7 (64-bit) registry

    Quote Originally Posted by dilettante View Post
    Perhaps you haven't heard about WOW64 registry redirection.

    The attachment shows how to get the information you want (and more).
    I just created an account simply so that I could reply to your solution and say THANK YOU. Extremely helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width