How to read the hardware configuration of Windows PC?
How to read the hardware configuration of Windows PC?
Hello,
I hope someone can help me out to find which purebasic syntax /command that allows me to examine the computer and find out the system configuration like chip set used, and other information unique to the computer .
I did vaguely remember such a function but just forgot which one to use.
Pls help.
Thanks
Alan
I hope someone can help me out to find which purebasic syntax /command that allows me to examine the computer and find out the system configuration like chip set used, and other information unique to the computer .
I did vaguely remember such a function but just forgot which one to use.
Pls help.
Thanks
Alan
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: How to read the hardware configuration of Windows PC?
That generally requires Windows API, so be specific about the exact values you need to collect.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: How to read the hardware configuration of Windows PC?
Thanks for your response..IdeasVacuum wrote:That generally requires Windows API, so be specific about the exact values you need to collect.
When I used "c:\systeminfo" on command line I can get these...
However, I need to to be able to get them from my purebasic program automatically and directly rather than doing it physically .Host Name: USER-PC
OS Name: Microsoft Windows 7 Starter
OS Version: 6.1.7601 Service Pack 1 Build 7601
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: user
Registered Organization:
Product ID: 00342-OEM-8634133-17179
Original Install Date: 7/10/2012, 12:08:52 AM
System Boot Time: 7/11/2012, 7:55:20 PM
System Manufacturer: Intel Corporation
System Model: Intel powered classmate PC
System Type: X86-based PC
Processor(s): 1 Processor(s) Installed.
[01]: x64 Family 6 Model 54 Stepping 1 GenuineIntel ~1600 Mhz
BIOS Version: Phoenix Technologies Ltd. TPCDV10L.86A.0042.2012.0510.1425, 5/10/2012
Windows Directory: C:\Windows
System Directory: C:\Windows\system32
Boot Device: \Device\HarddiskVolume1
System Locale: en-us;English (United States)
Input Locale: en-us;English (United States)
Time Zone: (UTC+08:00) Kuala Lumpur, Singapore
Total Physical Memory: 2,028 MB
Available Physical Memory: 1,445 MB
Virtual Memory: Max Size: 4,057 MB
Virtual Memory: Available: 3,234 MB
Virtual Memory: In Use: 823 MB
the Values I am particularly looking for are
OS Name: Microsoft Windows 7 Starter
OS Version: 6.1.7601 Service Pack 1 Build 7601
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
Product ID: 00342-OEM-8634133-17179
System Model: Intel powered classmate PC
System Type: X86-based PC
Processor(s): 1 Processor(s) Installed.
[01]: x64 Family 6 Model 54 Stepping 1 GenuineIntel ~1600 Mhz
Is there a sample script for me to refer to?
Rgds
Alan
Re: How to read the hardware configuration of Windows PC?
why not:
RunProgram("systeminfo > toto.txt")
then searching toto.txt?
RunProgram("systeminfo > toto.txt")
then searching toto.txt?
PureBasic: Surprisingly simple, diabolically powerful
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: How to read the hardware configuration of Windows PC?
systeminfo is not present on all Windows. On XP for example, it is on XP Professional but not XP Home, so your app cannot rely on it's availability.
There is code dotted around the forum though:
There is code dotted around the forum though:
Code: Select all
Declare CpuArchitecture()
Declare.s GetOsVersn()
Declare.s OSbits()
Declare.s GetOsServicePack()
Declare.s GetWindowsProductKey()
Declare.s GetCpuName()
Declare.q GetCpuNumber()
Declare.s GetPcName()
Global sgProcessorArchitecture.s = ""
Global sgPageSize.s = ""
Global sgNumberOfProcessors.s = ""
Import "kernel32.lib"
GlobalMemoryStatusEx.i(*lpBuffer)
EndImport
Procedure CpuArchitecture()
;--------------------------
#PROCESSOR_ARCHITECTURE_INTEL = 0
#PROCESSOR_ARCHITECTURE_MIPS = 1
#PROCESSOR_ARCHITECTURE_ALPHA = 2
#PROCESSOR_ARCHITECTURE_PPC = 3
#PROCESSOR_ARCHITECTURE_IA64 = 6
#PROCESSOR_ARCHITECTURE_AMD64 = 9 ; = AMD or Intel 64bit processor (std defined by AMD)
#PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF
GetSystemInfo_(ThisSystemInfo.SYSTEM_INFO)
Select ThisSystemInfo\wProcessorArchitecture
Case #PROCESSOR_ARCHITECTURE_AMD64 : sgProcessorArchitecture = "CPU Architecture: x64 (AMD or Intel)"
Case #PROCESSOR_ARCHITECTURE_IA64 : sgProcessorArchitecture = "CPU Architecture: Intel Itanium"
Case #PROCESSOR_ARCHITECTURE_INTEL : sgProcessorArchitecture = "CPU Architecture: x86"
Case #PROCESSOR_ARCHITECTURE_MIPS : sgProcessorArchitecture = "CPU Architecture: MIPS"
Case #PROCESSOR_ARCHITECTURE_ALPHA : sgProcessorArchitecture = "CPU Architecture: ALPHA"
Case #PROCESSOR_ARCHITECTURE_PPC : sgProcessorArchitecture = "CPU Architecture: Power PC"
Default : sgProcessorArchitecture = "CPU Architecture: Unknown"
EndSelect
sgPageSize = Str(ThisSystemInfo\dwPageSize)
sgNumberOfProcessors = Str(ThisSystemInfo\dwNumberOfProcessors)
EndProcedure
Procedure.s GetOsVersn()
;----------------------
sVersion.s = ""
Select OSVersion()
Case #PB_OS_Windows_NT3_51: sVersion = "Windows NT3.51"
Case #PB_OS_Windows_95: sVersion = "Windows 95"
Case #PB_OS_Windows_NT_4: sVersion = "Windows NT4"
Case #PB_OS_Windows_98: sVersion = "Windows 98"
Case #PB_OS_Windows_ME: sVersion = "Windows ME"
Case #PB_OS_Windows_2000: sVersion = "Windows 2000"
Case #PB_OS_Windows_XP: sVersion = "Windows XP"
Case #PB_OS_Windows_Server_2003: sVersion = "Windows Server 2003"
Case #PB_OS_Windows_Vista: sVersion = "Windows Vista"
Case #PB_OS_Windows_Server_2008: sVersion = "Windows Server 2008"
Case #PB_OS_Windows_7: sVersion = "Windows 7"
Case #PB_OS_Windows_Future: sVersion = "Windows 8"
Default: sVersion = "Windows Version not identified"
EndSelect
ProcedureReturn sVersion
EndProcedure
Procedure.s OSbits()
;-------------------
; Check if the OS is 32 or 64 bit.
;
Protected Is64BitOS = 0
Protected hDLL, IsWow64Process_
Protected sOSbits.s = "32"
If SizeOf(Integer) = 8
sOSbits = "64"
Else
hDll = OpenLibrary(#PB_Any,"kernel32.dll")
If hDll
IsWow64Process_ = GetFunction(hDll,"IsWow64Process")
If IsWow64Process_
CallFunctionFast(IsWow64Process_, GetCurrentProcess_(), @Is64BitOS)
EndIf
CloseLibrary(hDll)
EndIf
If(Is64BitOS = 1) : sOSbits = "64" : EndIf
EndIf
ProcedureReturn sOSbits
EndProcedure
Procedure.s GetOsServicePack()
;-----------------------------
OSVerInfo.OSVERSIONINFOEX
OSVerInfo\dwOSVersionInfoSize = SizeOf(OSVERSIONINFOEX)
GetVersionEx_(@OSVerInfo)
sServicePack.s = "SP" + Str(OSVerInfo\wServicePackMajor) + "." + Str(OSVerInfo\wServicePackMinor) + " [Build " + Str(OSVerInfo\dwBuildNumber) + "]"
ProcedureReturn sServicePack
EndProcedure
Procedure.s GetWindowsProductKey()
;---------------------------------
#KEY_WOW64_64KEY = $100
Protected hKey, Res, size = 280
Protected i, j, x, Result.s
Protected *mem = AllocateMemory(size)
Protected *newmem = AllocateMemory(size)
Protected *digits = AllocateMemory(25)
PokeS(*digits, "BCDFGHJKMPQRTVWXY2346789", -1, #PB_Ascii)
If OSVersion() <= #PB_OS_Windows_2000
Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", 0, #KEY_READ, @hKey)
Else
Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", 0, #KEY_READ | #KEY_WOW64_64KEY, @hKey)
EndIf
If Res = #ERROR_SUCCESS
RegQueryValueEx_(hKey, "DigitalProductID", 0, 0, *mem, @size)
RegCloseKey_(hKey)
If size <> 280
For i = 24 To 0 Step -1
x = 0
For j = 66 To 52 Step -1
x = (x << 8) + PeekA(*mem + j)
PokeA(*mem + j, x / 24)
x % 24
Next
PokeA(*newmem + i, PeekA(*digits + x))
Next
For i = 0 To 15 Step 5
Result + PeekS(*newmem + i, 5, #PB_Ascii) + "-"
Next
Result + PeekS(*newmem + 20, 5, #PB_Ascii)
EndIf
EndIf
FreeMemory(*mem) : FreeMemory(*newmem) : FreeMemory(*digits)
ProcedureReturn Result
EndProcedure
Procedure.s GetCpuName()
;-----------------------
Protected sBuffer.s
Protected Zeiger1.i, Zeiger2.i, Zeiger3.i, Zeiger4.i
!MOV eax, $80000002
!CPUID
; the CPU-Name is now stored in EAX-EBX-ECX-EDX
!MOV [p.v_Zeiger1], EAX ; move eax to the buffer
!MOV [p.v_Zeiger2], EBX ; move ebx to the buffer
!MOV [p.v_Zeiger3], ECX ; move ecx to the buffer
!MOV [p.v_Zeiger4], EDX ; move edx to the buffer
;Now move the content of Zeiger (4*4=16 Bytes to a string
sBuffer = PeekS(@Zeiger1, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii)
;Second Part of the Name
!MOV eax, $80000003
!CPUID
; the CPU-Name is now stored in EAX-EBX-ECX-EDX
!MOV [p.v_Zeiger1], EAX ; move eax to the buffer
!MOV [p.v_Zeiger2], EBX ; move ebx to the buffer
!MOV [p.v_Zeiger3], ECX ; move ecx to the buffer
!MOV [p.v_Zeiger4], EDX ; move edx to the buffer
;Now move the content of Zeiger (4*4=16 Bytes to a string
sBuffer + PeekS(@Zeiger1, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii)
;Third Part of the Name
!MOV eax, $80000004
!CPUID
; the CPU-Name is now stored in EAX-EBX-ECX-EDX
!MOV [p.v_Zeiger1], EAX ; move eax to the buffer
!MOV [p.v_Zeiger2], EBX ; move ebx to the buffer
!MOV [p.v_Zeiger3], ECX ; move ecx to the buffer
!MOV [p.v_Zeiger4], EDX ; move edx to the buffer
;Now move the content of Zeiger (4*4=16 Bytes to a string
sBuffer + PeekS(@Zeiger1, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii)
sCpuName.s = RemoveString(sBuffer," ",#PB_String_NoCase)
ProcedureReturn sCpuName
EndProcedure
Procedure.q GetCpuNumber()
;-------------------------
Define highbits.l
Define lowbits.l
Define serial.q
!MOV eax, $80000003
!CPUID
!MOV dword [p.v_lowbits], ecx
!MOV dword [p.v_highbits], edx
serial = lowbits | highbits << 32
ProcedureReturn serial
EndProcedure
Procedure.s GetPcName()
;----------------------
Protected sComputerName.s = GetEnvironmentVariable("COMPUTERNAME")
If sComputerName
sComputerName = "Computer Name: " + sComputerName
Else
sComputerName = "Not Found"
EndIf
ProcedureReturn(sComputerName)
EndProcedure
;==== TEST ========
CpuArchitecture()
Debug sgProcessorArchitecture
Debug sgPageSize
Debug sgNumberOfProcessors
Debug GetOsVersn()
Debug OSbits()
Debug GetOsServicePack()
Debug GetWindowsProductKey()
Debug GetCpuName()
Debug GetCpuNumber()
Debug GetPcName()
Last edited by IdeasVacuum on Thu Jul 12, 2012 11:26 am, edited 2 times in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: How to read the hardware configuration of Windows PC?
Why ExamineEnvironmentVariables()?
Code: Select all
Procedure.s GetPcName()
Protected sComputerName.s = GetEnvironmentVariable("COMPUTERNAME")
If sComputerName
sComputerName = "Computer Name: " + sComputerName
Else
sComputerName = "Not Found"
EndIf
ProcedureReturn sComputerName
EndProcedure
Debug GetPcName()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: How to read the hardware configuration of Windows PC?
No idea.Why ExamineEnvironmentVariables()?

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: How to read the hardware configuration of Windows PC?
What can be the reason why GetPcName() returns
"32" instead "64" on my system? All other Procedures
returned reasonable results. sgProcessorArchitecture
gives "CPU Architecture c64(AMD or Intel).
I've got Windows 7 - 64Bit installed and compiled
the program incl. GetPcName() using PB 4.61(x64).
"32" instead "64" on my system? All other Procedures
returned reasonable results. sgProcessorArchitecture
gives "CPU Architecture c64(AMD or Intel).
I've got Windows 7 - 64Bit installed and compiled
the program incl. GetPcName() using PB 4.61(x64).

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: How to read the hardware configuration of Windows PC?
I think you mean the OSbits() Procedure? Try this:
There is an even better way that Luis explains, I'll see if I can dig that up too.
Code: Select all
Procedure.l QueryValueEx(lhkey.i, szValueName.s)
;-----------------------------------------------
Define.i cch, lrc, lType, lValue
Define.s sValue
vValue.s
cch = 255
sValue = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue, @cch)
If lrc = 0
vValue = Left(sValue, cch - 1)
Else
vValue = "Empty"
EndIf
ProcedureReturn lrc
EndProcedure
Procedure.s OSbits()
;-------------------
lRetVal.l = 0
lHKeyhandle.l = 0
lhkey.l = 0
sOSbits.s = "32bit"
lTopLevelKey.l = #HKEY_LOCAL_MACHINE
sRemMachName.s = ""
sKeyName.s = "Software\Microsoft\Windows\CurrentVersion"
sValueName.s = "CommonW6432Dir"
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0,#KEY_READ, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If lRetVal = 0 : sOSbits = "64bit" : EndIf
ProcedureReturn sOSbits
EndProcedure
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: How to read the hardware configuration of Windows PC?
OK, the original code at the top of the post has been updated with a better GetOSbits Procedure that works if compiled by PB 32bit or 64bit (Thanks to Luis). Also included ts-soft's GetPcName Procedure which does the job nicely.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: How to read the hardware configuration of Windows PC?
Dear IdeasVacuum,'IdeasVacuum wrote:systeminfo is not present on all Windows. On XP for example, it is on XP Professional but not XP Home, so your app cannot rely on it's availability.
There is code dotted around the forum though:Code: Select all
Declare CpuArchitecture() Declare.s GetOsVersn() Declare.s OSbits() Declare.s GetOsServicePack() Declare.s GetWindowsProductKey() Declare.s GetCpuName() Declare.q GetCpuNumber() Declare.s GetPcName() Global sgProcessorArchitecture.s = "" Global sgPageSize.s = "" Global sgNumberOfProcessors.s = "" Import "kernel32.lib" GlobalMemoryStatusEx.i(*lpBuffer) EndImport Procedure CpuArchitecture() ;-------------------------- #PROCESSOR_ARCHITECTURE_INTEL = 0 #PROCESSOR_ARCHITECTURE_MIPS = 1 #PROCESSOR_ARCHITECTURE_ALPHA = 2 #PROCESSOR_ARCHITECTURE_PPC = 3 #PROCESSOR_ARCHITECTURE_IA64 = 6 #PROCESSOR_ARCHITECTURE_AMD64 = 9 ; = AMD or Intel 64bit processor (std defined by AMD) #PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF GetSystemInfo_(ThisSystemInfo.SYSTEM_INFO) Select ThisSystemInfo\wProcessorArchitecture Case #PROCESSOR_ARCHITECTURE_AMD64 : sgProcessorArchitecture = "CPU Architecture: x64 (AMD or Intel)" Case #PROCESSOR_ARCHITECTURE_IA64 : sgProcessorArchitecture = "CPU Architecture: Intel Itanium" Case #PROCESSOR_ARCHITECTURE_INTEL : sgProcessorArchitecture = "CPU Architecture: x86" Case #PROCESSOR_ARCHITECTURE_MIPS : sgProcessorArchitecture = "CPU Architecture: MIPS" Case #PROCESSOR_ARCHITECTURE_ALPHA : sgProcessorArchitecture = "CPU Architecture: ALPHA" Case #PROCESSOR_ARCHITECTURE_PPC : sgProcessorArchitecture = "CPU Architecture: Power PC" Default : sgProcessorArchitecture = "CPU Architecture: Unknown" EndSelect sgPageSize = Str(ThisSystemInfo\dwPageSize) sgNumberOfProcessors = Str(ThisSystemInfo\dwNumberOfProcessors) EndProcedure Procedure.s GetOsVersn() ;---------------------- sVersion.s = "" Select OSVersion() Case #PB_OS_Windows_NT3_51: sVersion = "Windows NT3.51" Case #PB_OS_Windows_95: sVersion = "Windows 95" Case #PB_OS_Windows_NT_4: sVersion = "Windows NT4" Case #PB_OS_Windows_98: sVersion = "Windows 98" Case #PB_OS_Windows_ME: sVersion = "Windows ME" Case #PB_OS_Windows_2000: sVersion = "Windows 2000" Case #PB_OS_Windows_XP: sVersion = "Windows XP" Case #PB_OS_Windows_Server_2003: sVersion = "Windows Server 2003" Case #PB_OS_Windows_Vista: sVersion = "Windows Vista" Case #PB_OS_Windows_Server_2008: sVersion = "Windows Server 2008" Case #PB_OS_Windows_7: sVersion = "Windows 7" Case #PB_OS_Windows_Future: sVersion = "Windows 8" Default: sVersion = "Windows Version not identified" EndSelect ProcedureReturn sVersion EndProcedure Procedure.s OSbits() ;------------------- ; Check if the OS is 32 or 64 bit. ; Protected Is64BitOS = 0 Protected hDLL, IsWow64Process_ Protected sOSbits.s = "32" If SizeOf(Integer) = 8 sOSbits = "64" Else hDll = OpenLibrary(#PB_Any,"kernel32.dll") If hDll IsWow64Process_ = GetFunction(hDll,"IsWow64Process") If IsWow64Process_ CallFunctionFast(IsWow64Process_, GetCurrentProcess_(), @Is64BitOS) EndIf CloseLibrary(hDll) EndIf If(Is64BitOS = 1) : sOSbits = "64" : EndIf EndIf ProcedureReturn sOSbits EndProcedure Procedure.s GetOsServicePack() ;----------------------------- OSVerInfo.OSVERSIONINFOEX OSVerInfo\dwOSVersionInfoSize = SizeOf(OSVERSIONINFOEX) GetVersionEx_(@OSVerInfo) sServicePack.s = "SP" + Str(OSVerInfo\wServicePackMajor) + "." + Str(OSVerInfo\wServicePackMinor) + " [Build " + Str(OSVerInfo\dwBuildNumber) + "]" ProcedureReturn sServicePack EndProcedure Procedure.s GetWindowsProductKey() ;--------------------------------- #KEY_WOW64_64KEY = $100 Protected hKey, Res, size = 280 Protected i, j, x, Result.s Protected *mem = AllocateMemory(size) Protected *newmem = AllocateMemory(size) Protected *digits = AllocateMemory(25) PokeS(*digits, "BCDFGHJKMPQRTVWXY2346789", -1, #PB_Ascii) If OSVersion() <= #PB_OS_Windows_2000 Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", 0, #KEY_READ, @hKey) Else Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", 0, #KEY_READ | #KEY_WOW64_64KEY, @hKey) EndIf If Res = #ERROR_SUCCESS RegQueryValueEx_(hKey, "DigitalProductID", 0, 0, *mem, @size) RegCloseKey_(hKey) If size <> 280 For i = 24 To 0 Step -1 x = 0 For j = 66 To 52 Step -1 x = (x << 8) + PeekA(*mem + j) PokeA(*mem + j, x / 24) x % 24 Next PokeA(*newmem + i, PeekA(*digits + x)) Next For i = 0 To 15 Step 5 Result + PeekS(*newmem + i, 5, #PB_Ascii) + "-" Next Result + PeekS(*newmem + 20, 5, #PB_Ascii) EndIf EndIf FreeMemory(*mem) : FreeMemory(*newmem) : FreeMemory(*digits) ProcedureReturn Result EndProcedure Procedure.s GetCpuName() ;----------------------- Protected sBuffer.s Protected Zeiger1.i, Zeiger2.i, Zeiger3.i, Zeiger4.i !MOV eax, $80000002 !CPUID ; the CPU-Name is now stored in EAX-EBX-ECX-EDX !MOV [p.v_Zeiger1], EAX ; move eax to the buffer !MOV [p.v_Zeiger2], EBX ; move ebx to the buffer !MOV [p.v_Zeiger3], ECX ; move ecx to the buffer !MOV [p.v_Zeiger4], EDX ; move edx to the buffer ;Now move the content of Zeiger (4*4=16 Bytes to a string sBuffer = PeekS(@Zeiger1, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii) ;Second Part of the Name !MOV eax, $80000003 !CPUID ; the CPU-Name is now stored in EAX-EBX-ECX-EDX !MOV [p.v_Zeiger1], EAX ; move eax to the buffer !MOV [p.v_Zeiger2], EBX ; move ebx to the buffer !MOV [p.v_Zeiger3], ECX ; move ecx to the buffer !MOV [p.v_Zeiger4], EDX ; move edx to the buffer ;Now move the content of Zeiger (4*4=16 Bytes to a string sBuffer + PeekS(@Zeiger1, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii) ;Third Part of the Name !MOV eax, $80000004 !CPUID ; the CPU-Name is now stored in EAX-EBX-ECX-EDX !MOV [p.v_Zeiger1], EAX ; move eax to the buffer !MOV [p.v_Zeiger2], EBX ; move ebx to the buffer !MOV [p.v_Zeiger3], ECX ; move ecx to the buffer !MOV [p.v_Zeiger4], EDX ; move edx to the buffer ;Now move the content of Zeiger (4*4=16 Bytes to a string sBuffer + PeekS(@Zeiger1, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii) sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii) sCpuName.s = RemoveString(sBuffer," ",#PB_String_NoCase) ProcedureReturn sCpuName EndProcedure Procedure.q GetCpuNumber() ;------------------------- Define highbits.l Define lowbits.l Define serial.q !MOV eax, $80000003 !CPUID !MOV dword [p.v_lowbits], ecx !MOV dword [p.v_highbits], edx serial = lowbits | highbits << 32 ProcedureReturn serial EndProcedure Procedure.s GetPcName() ;---------------------- Protected sComputerName.s = GetEnvironmentVariable("COMPUTERNAME") If sComputerName sComputerName = "Computer Name: " + sComputerName Else sComputerName = "Not Found" EndIf ProcedureReturn(sComputerName) EndProcedure ;==== TEST ======== CpuArchitecture() Debug sgProcessorArchitecture Debug sgPageSize Debug sgNumberOfProcessors Debug GetOsVersn() Debug OSbits() Debug GetOsServicePack() Debug GetWindowsProductKey() Debug GetCpuName() Debug GetCpuNumber() Debug GetPcName()
Thank you so much for your help. So very glad to be able to get the values.
REgards
Alan
Re: How to read the hardware configuration of Windows PC?
Thanks. This works for my 64 bit, too.IdeasVacuum wrote:OK, the original code at the top of the post has been updated with a better GetOSbits Procedure that works if compiled by PB 32bit or 64bit (Thanks to Luis). Also included ts-soft's GetPcName Procedure which does the job nicely.

Re: How to read the hardware configuration of Windows PC?
CpuArchitecture() returns "CPU Architecture: x86" on Windows/64bit with PB/32bit, but CpuArchitecture() should return "CPU Architecture: x64 (AMD or Intel)".
Maybe it's better to call GetNativeSystemInfo_() on XP+ systems?
I also out-commented Itanium, MIPS, Alpha, and PowerPC - PB/Windows does not compile on those platforms, yet. (maybe #PROCESSOR_ARCHITECTURE_ARM for PB/Win8 support in the near future?
)
Maybe it's better to call GetNativeSystemInfo_() on XP+ systems?
I also out-commented Itanium, MIPS, Alpha, and PowerPC - PB/Windows does not compile on those platforms, yet. (maybe #PROCESSOR_ARCHITECTURE_ARM for PB/Win8 support in the near future?

Code: Select all
; Import "Kernel32.lib"
; CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
; GetNativeSystemInfo_(*si.SYSTEM_INFO) As "_GetNativeSystemInfo@4"
; CompilerElse
; GetNativeSystemInfo_(*si.SYSTEM_INFO) As "GetNativeSystemInfo"
; CompilerEndIf
; EndImport
Declare CpuArchitecture()
Declare.s GetOsVersn()
Declare.s OSbits()
Declare.s GetOsServicePack()
Declare.s GetWindowsProductKey()
Declare.s GetCpuName()
Declare.q GetCpuNumber()
Declare.s GetPcName()
Global sgProcessorArchitecture.s = ""
Global sgPageSize.s = ""
Global sgNumberOfProcessors.s = ""
Import "kernel32.lib"
GlobalMemoryStatusEx.i(*lpBuffer)
EndImport
Procedure CpuArchitecture()
;--------------------------
#PROCESSOR_ARCHITECTURE_INTEL = 0
#PROCESSOR_ARCHITECTURE_MIPS = 1
#PROCESSOR_ARCHITECTURE_ALPHA = 2
#PROCESSOR_ARCHITECTURE_PPC = 3
#PROCESSOR_ARCHITECTURE_IA64 = 6
#PROCESSOR_ARCHITECTURE_AMD64 = 9 ; = AMD or Intel 64bit processor (std defined by AMD)
#PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF
Protected ThisSystemInfo.SYSTEM_INFO
If OSVersion() < #PB_OS_Windows_XP
GetSystemInfo_(ThisSystemInfo)
Else
;GetNativeSystemInfo_(ThisSystemInfo.SYSTEM_INFO) ; do not use 'Import', use OpenLibrary instead
Protected OK, hDLL, GetNativeSystemInfo_
hDll = OpenLibrary(#PB_Any,"kernel32.dll")
If hDll
GetNativeSystemInfo_ = GetFunction(hDll,"GetNativeSystemInfo")
If GetNativeSystemInfo_
CallFunctionFast(GetNativeSystemInfo_, ThisSystemInfo.SYSTEM_INFO)
OK = #True
EndIf
CloseLibrary(hDll)
EndIf
If Not OK
GetSystemInfo_(ThisSystemInfo)
EndIf
EndIf
Select ThisSystemInfo\wProcessorArchitecture
Case #PROCESSOR_ARCHITECTURE_AMD64 : sgProcessorArchitecture = "CPU Architecture: x64 (AMD or Intel)"
;Case #PROCESSOR_ARCHITECTURE_IA64 : sgProcessorArchitecture = "CPU Architecture: Intel Itanium"
Case #PROCESSOR_ARCHITECTURE_INTEL : sgProcessorArchitecture = "CPU Architecture: x86"
;Case #PROCESSOR_ARCHITECTURE_MIPS : sgProcessorArchitecture = "CPU Architecture: MIPS"
;Case #PROCESSOR_ARCHITECTURE_ALPHA : sgProcessorArchitecture = "CPU Architecture: ALPHA"
;Case #PROCESSOR_ARCHITECTURE_PPC : sgProcessorArchitecture = "CPU Architecture: Power PC"
Default : sgProcessorArchitecture = "CPU Architecture: Unknown"
EndSelect
sgPageSize = Str(ThisSystemInfo\dwPageSize)
sgNumberOfProcessors = Str(ThisSystemInfo\dwNumberOfProcessors)
EndProcedure
Procedure.s GetOsVersn()
;----------------------
sVersion.s = ""
Select OSVersion()
Case #PB_OS_Windows_NT3_51: sVersion = "Windows NT3.51"
Case #PB_OS_Windows_95: sVersion = "Windows 95"
Case #PB_OS_Windows_NT_4: sVersion = "Windows NT4"
Case #PB_OS_Windows_98: sVersion = "Windows 98"
Case #PB_OS_Windows_ME: sVersion = "Windows ME"
Case #PB_OS_Windows_2000: sVersion = "Windows 2000"
Case #PB_OS_Windows_XP: sVersion = "Windows XP"
Case #PB_OS_Windows_Server_2003: sVersion = "Windows Server 2003"
Case #PB_OS_Windows_Vista: sVersion = "Windows Vista"
Case #PB_OS_Windows_Server_2008: sVersion = "Windows Server 2008"
Case #PB_OS_Windows_7: sVersion = "Windows 7"
Case #PB_OS_Windows_Future: sVersion = "Windows 8"
Default: sVersion = "Windows Version not identified"
EndSelect
ProcedureReturn sVersion
EndProcedure
Procedure.s OSbits()
;-------------------
; Check if the OS is 32 or 64 bit.
;
Protected Is64BitOS = 0
Protected hDLL, IsWow64Process_
Protected sOSbits.s = "32"
If SizeOf(Integer) = 8
sOSbits = "64"
Else
hDll = OpenLibrary(#PB_Any,"kernel32.dll")
If hDll
IsWow64Process_ = GetFunction(hDll,"IsWow64Process")
If IsWow64Process_
CallFunctionFast(IsWow64Process_, GetCurrentProcess_(), @Is64BitOS)
EndIf
CloseLibrary(hDll)
EndIf
If(Is64BitOS = 1) : sOSbits = "64" : EndIf
EndIf
ProcedureReturn sOSbits
EndProcedure
Procedure.s GetOsServicePack()
;-----------------------------
OSVerInfo.OSVERSIONINFOEX
OSVerInfo\dwOSVersionInfoSize = SizeOf(OSVERSIONINFOEX)
GetVersionEx_(@OSVerInfo)
sServicePack.s = "SP" + Str(OSVerInfo\wServicePackMajor) + "." + Str(OSVerInfo\wServicePackMinor) + " [Build " + Str(OSVerInfo\dwBuildNumber) + "]"
ProcedureReturn sServicePack
EndProcedure
Procedure.s GetWindowsProductKey()
;---------------------------------
#KEY_WOW64_64KEY = $100
Protected hKey, Res, size = 280
Protected i, j, x, Result.s
Protected *mem = AllocateMemory(size)
Protected *newmem = AllocateMemory(size)
Protected *digits = AllocateMemory(25)
PokeS(*digits, "BCDFGHJKMPQRTVWXY2346789", -1, #PB_Ascii)
If OSVersion() <= #PB_OS_Windows_2000
Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", 0, #KEY_READ, @hKey)
Else
Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", 0, #KEY_READ | #KEY_WOW64_64KEY, @hKey)
EndIf
If Res = #ERROR_SUCCESS
RegQueryValueEx_(hKey, "DigitalProductID", 0, 0, *mem, @size)
RegCloseKey_(hKey)
If size <> 280
For i = 24 To 0 Step -1
x = 0
For j = 66 To 52 Step -1
x = (x << 8) + PeekA(*mem + j)
PokeA(*mem + j, x / 24)
x % 24
Next
PokeA(*newmem + i, PeekA(*digits + x))
Next
For i = 0 To 15 Step 5
Result + PeekS(*newmem + i, 5, #PB_Ascii) + "-"
Next
Result + PeekS(*newmem + 20, 5, #PB_Ascii)
EndIf
EndIf
FreeMemory(*mem) : FreeMemory(*newmem) : FreeMemory(*digits)
ProcedureReturn Result
EndProcedure
Procedure.s GetCpuName()
;-----------------------
Protected sBuffer.s
Protected Zeiger1.i, Zeiger2.i, Zeiger3.i, Zeiger4.i
!MOV eax, $80000002
!CPUID
; the CPU-Name is now stored in EAX-EBX-ECX-EDX
!MOV [p.v_Zeiger1], EAX ; move eax to the buffer
!MOV [p.v_Zeiger2], EBX ; move ebx to the buffer
!MOV [p.v_Zeiger3], ECX ; move ecx to the buffer
!MOV [p.v_Zeiger4], EDX ; move edx to the buffer
;Now move the content of Zeiger (4*4=16 Bytes to a string
sBuffer = PeekS(@Zeiger1, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii)
;Second Part of the Name
!MOV eax, $80000003
!CPUID
; the CPU-Name is now stored in EAX-EBX-ECX-EDX
!MOV [p.v_Zeiger1], EAX ; move eax to the buffer
!MOV [p.v_Zeiger2], EBX ; move ebx to the buffer
!MOV [p.v_Zeiger3], ECX ; move ecx to the buffer
!MOV [p.v_Zeiger4], EDX ; move edx to the buffer
;Now move the content of Zeiger (4*4=16 Bytes to a string
sBuffer + PeekS(@Zeiger1, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii)
;Third Part of the Name
!MOV eax, $80000004
!CPUID
; the CPU-Name is now stored in EAX-EBX-ECX-EDX
!MOV [p.v_Zeiger1], EAX ; move eax to the buffer
!MOV [p.v_Zeiger2], EBX ; move ebx to the buffer
!MOV [p.v_Zeiger3], ECX ; move ecx to the buffer
!MOV [p.v_Zeiger4], EDX ; move edx to the buffer
;Now move the content of Zeiger (4*4=16 Bytes to a string
sBuffer + PeekS(@Zeiger1, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger2, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger3, 4, #PB_Ascii)
sBuffer + PeekS(@Zeiger4, 4, #PB_Ascii)
sCpuName.s = RemoveString(sBuffer," ",#PB_String_NoCase)
ProcedureReturn sCpuName
EndProcedure
Procedure.q GetCpuNumber()
;-------------------------
Define highbits.l
Define lowbits.l
Define serial.q
!MOV eax, $80000003
!CPUID
!MOV dword [p.v_lowbits], ecx
!MOV dword [p.v_highbits], edx
serial = lowbits | highbits << 32
ProcedureReturn serial
EndProcedure
Procedure.s GetPcName()
;----------------------
Protected sComputerName.s = GetEnvironmentVariable("COMPUTERNAME")
If sComputerName
sComputerName = "Computer Name: " + sComputerName
Else
sComputerName = "Not Found"
EndIf
ProcedureReturn(sComputerName)
EndProcedure
;==== TEST ========
CpuArchitecture()
Debug sgProcessorArchitecture
Debug sgPageSize
Debug sgNumberOfProcessors
Debug GetOsVersn()
Debug OSbits()
Debug GetOsServicePack()
Debug GetWindowsProductKey()
Debug GetCpuName()
Debug GetCpuNumber()
Debug GetPcName()
Re: How to read the hardware configuration of Windows PC?
Hello at all.
I've search a code to read 0Windows 10 productkey, and found this very good source here.
But i found any script with Powershell, it give me an another Productkey. What must be changed for that
to becomes the same key?
Here a Powershellscript for all Versions:
http://www.wintotal.de/?p=7893
http://www.wintotal.de/media/2014/02/GetWinKey.zip
(sorry my engish)
Thank you and regards from germany,
Falko
I've search a code to read 0Windows 10 productkey, and found this very good source here.
But i found any script with Powershell, it give me an another Productkey. What must be changed for that
to becomes the same key?
Here a Powershellscript for all Versions:
http://www.wintotal.de/?p=7893
http://www.wintotal.de/media/2014/02/GetWinKey.zip
(sorry my engish)
Thank you and regards from germany,
Falko
Re: How to read the hardware configuration of Windows PC?
dont work on W10