How to read the hardware configuration of Windows PC?

Just starting out? Need help? Post your questions and find answers here.
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to read the hardware configuration of Windows PC?

Post by skywalk »

For Windows, try wmic cmd's and parse the output.

Code: Select all

c:\>wmic computersystem list brief /format:csv
c:\>wmic os get "SerialNumber" /value|find "="
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Falko
Enthusiast
Enthusiast
Posts: 271
Joined: Sat Oct 04, 2003 12:57 pm
Location: Germany
Contact:

Re: How to read the hardware configuration of Windows PC?

Post by Falko »

sorry, this is not a ProductKey.

I've found this here but it works not for me:
C:\>wmic path softwarelicensingservice get OA3xOriginalProductKey
www.falko-pure.de
Win11 Pro 64-Bit, PB_6.11b1
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: How to read the hardware configuration of Windows PC?

Post by JHPJHP »

Hi Falko,

Try the following: Updated
- modified / converted an old vbScript I had lying around

Code: Select all

Procedure.s ConvertToKey(*DigitalID)
  #KeyOffset = 52

  If OSVersion() >= #PB_OS_Windows_8 : PokeA(*DigitalID + 66, 1) : EndIf

  Characters.s = "BCDFGHJKMPQRTVWXY2346789"
  nLength = Len(Characters)

  For rtnCount = nLength To 0 Step -1
    nCurrent = 0

    For x = 14 To 0 Step -1
      nCurrent * 256
      nCurrent + PeekA(*DigitalID + x + #KeyOffset)
      PokeA(*DigitalID + x + #KeyOffset, nCurrent / nLength)
      nCurrent = Mod(nCurrent, nLength)
    Next
    KeyOutput.s = Mid(Characters, nCurrent + 1, 1) + KeyOutput
  Next

  If OSVersion() < #PB_OS_Windows_8 : nStart = 1 : Else : nStart = 2 : EndIf

  a.s = Mid(KeyOutput, nStart, 5)
  b.s = Mid(KeyOutput, 6, 5)
  c.s = Mid(KeyOutput, 11, 5)
  d.s = Mid(KeyOutput, 16, 5)
  e.s = Mid(KeyOutput, 21, 5)
  ProcedureReturn a + "-" + b + "-" + c + "-" + d + "-" + e
EndProcedure

Procedure GetRegistryValue(hKey, lpSubKey.s, lpValueName.s)
  #KEY_WOW64_64KEY = $100

  If RegOpenKeyEx_(hKey, lpSubKey, ulOptions, #KEY_QUERY_VALUE | #KEY_WOW64_64KEY, @phkResult) = #ERROR_SUCCESS
    If RegQueryValueEx_(phkResult, lpValueName, lpReserved, @lpType, #Null, @lpcbData) = #ERROR_SUCCESS
      If lpcbData
        *lpData = AllocateMemory(lpcbData)
        RegQueryValueEx_(phkResult, lpValueName, lpReserved, @lpType, *lpData, @lpcbData)
      EndIf
    EndIf
    RegCloseKey_(phkResult)
  EndIf
  ProcedureReturn *lpData
EndProcedure

lpSubKey.s = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"

*lpData = GetRegistryValue(#HKEY_LOCAL_MACHINE, lpSubKey, "ProductName")
Debug "Product Name: " + PeekS(*lpData) : FreeMemory(*lpData)

*lpData = GetRegistryValue(#HKEY_LOCAL_MACHINE, lpSubKey, "ProductId")
Debug "Product ID: " + PeekS(*lpData) : FreeMemory(*lpData)

*lpData = GetRegistryValue(#HKEY_LOCAL_MACHINE, lpSubKey, "DigitalProductId")
Debug "Product Key: " + ConvertToKey(*lpData) : FreeMemory(*lpData)
Added to my Services, Stuff, and Shellhook post: /Stuff/MoreStuff/GetProductKey.pb.
Last edited by JHPJHP on Mon Aug 03, 2015 4:13 pm, edited 3 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
User avatar
Falko
Enthusiast
Enthusiast
Posts: 271
Joined: Sat Oct 04, 2003 12:57 pm
Location: Germany
Contact:

Re: How to read the hardware configuration of Windows PC?

Post by Falko »

Hi JHPJHP,
thank you :)
www.falko-pure.de
Win11 Pro 64-Bit, PB_6.11b1
Post Reply