Recent

Author Topic: Getting System Information from the Windows Registry  (Read 9980 times)

OLLI_S

  • Full Member
  • ***
  • Posts: 119
Getting System Information from the Windows Registry
« on: October 05, 2019, 03:57:20 pm »
Hello,

I want to show in my application some system information that I want to read from the Registry.
Here I want to show the following components:

Processor
I found the processor name in the registry:
Code: Pascal  [Select][+][-]
  1. Registry-Path:        Computer\HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
  2. ProcessorNameString:  Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

I also see that below CentralProcessor there are the folders 0 to 7, so this way I can detect how many cores the processor has.
Or is there a better way to detect the number of cores?

Video-Card
Here I found in the registry:
Code: Pascal  [Select][+][-]
  1. Registry-Path:        Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinSAT
  2. PrimaryAdapterString: NVIDIA GeForce GTX 970
  3. VideoMemorySize:      4188692480

But where in the registry is the number of installed RAM (not video ram) stored?

Best regards

OLLI

winni

  • Hero Member
  • *****
  • Posts: 3121
Re: Getting System Information from the Windows Registry
« Reply #1 on: October 05, 2019, 04:30:10 pm »
Hi!

Use

HKLM\HARDWARE\RESOURCEMAP\System Resources\Physical Memory

This undocumented by M$ !

Winni

OLLI_S

  • Full Member
  • ***
  • Posts: 119
Re: Getting System Information from the Windows Registry
« Reply #2 on: October 05, 2019, 06:55:06 pm »
Hello winni,

here I see the key .Translated and the type ist REG_RESOURCE_LIST.
When I double-Click it, then a new widow opens with one entry.
If I double click this, a new window with multiple lists is opened.

One List is for my memory.
Here I have columns Physical Address and Length.
I have no idea how to read this...

Best regards

OLLI

440bx

  • Hero Member
  • *****
  • Posts: 2933
Re: Getting System Information from the Windows Registry
« Reply #3 on: October 05, 2019, 07:13:32 pm »
But where in the registry is the number of installed RAM (not video ram) stored?
I don't have the answer to that question (I am not fond of getting system information from the registry) but, Windows provides an API named "GetPhysicallyInstalledSystemMemory" that, as its name indicates, returns the physically installed amount of memory in KB (there are some caveats.)  The API's documentation is found at https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getphysicallyinstalledsystemmemory

You can find an example of calling it at https://forum.lazarus.freepascal.org/index.php/topic,45180.msg318906.html#msg318906

HTH

ETA:

I forgot to mention information you may be interested in regarding the number of cores found in the registry.  The registry key you are inspecting reports the number of logical cores, not physical cores (that number can sometimes be important.)  To determine the number of physical cores you can use the API "GetLogicalProcessorInformation" and interpret the data it returns to derive the number of physical cores.  An example is included in the page that documents the API, which is, https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getlogicalprocessorinformation
« Last Edit: October 05, 2019, 07:32:30 pm by 440bx »
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

OLLI_S

  • Full Member
  • ***
  • Posts: 119
Re: Getting System Information from the Windows Registry
« Reply #4 on: October 05, 2019, 07:47:47 pm »
Hello,

before there is any misunderstanding:
A friend of mine needs this for his application and it is programmed in C++.

I wanted to help him looking up the values in the registry (the CPU and GPU are stored there).
So I coded a little Lazarus app that reads the values and shows them in a simple TMemo control.
With my little tool I can test if the registry values are correctly for different computers I have at home / at work.

This is the reason why I only use the registry, no system functions.

Best regards

OLLI

OLLI_S

  • Full Member
  • ***
  • Posts: 119
Re: Getting System Information from the Windows Registry
« Reply #5 on: October 05, 2019, 10:18:25 pm »
Use

HKLM\HARDWARE\RESOURCEMAP\System Resources\Physical Memory

This undocumented by M$ !

I found an example how to read the memory size from this structure:
https://www.remkoweijnen.nl/blog/2009/03/20/reading-physical-memory-size-from-the-registry/

It is not trivial, it is more complicated.
So I will forward this information to my friend...

OLLI

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1129
    • Lebeau Software
Re: Getting System Information from the Windows Registry
« Reply #6 on: October 08, 2019, 12:25:31 am »
You really shouldn't be using the Registry to find system information.  Use pre-defined APIs that are designed for that purpose instead.  There are many API functions defined for getting system info.  Alternatively, WMI has a lot of system info in it, such as in the various Win32 Provider classes (like Win32_Processor, Win32_VideoController, etc).

I also see that below CentralProcessor there are the folders 0 to 7, so this way I can detect how many cores the processor has.
Or is there a better way to detect the number of cores?

Look at:

GetSystemInfo()

GetLogicalProcessorInformation()

GetLogicalProcessorInformationEx()

But where in the registry is the number of installed RAM (not video ram) stored?

GlobalMemoryStatusEx()

GetPhysicallyInstalledSystemMemory()
« Last Edit: October 08, 2019, 12:30:30 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

OLLI_S

  • Full Member
  • ***
  • Posts: 119
Re: Getting System Information from the Windows Registry
« Reply #7 on: October 08, 2019, 10:23:35 pm »
You really shouldn't be using the Registry to find system information.  Use pre-defined APIs that are designed for that purpose instead.
OK, I will try that out in Lazarus and then forward this to my friend.

But how do I get the Windows version and the exact build number of Windows like:
Windows 10 Pro 64-Bit Version 1903 (Build 18362.388)

Currently I also use the registry to get this information:
Code: Pascal  [Select][+][-]
  1. Registry-Path: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
  2. ProductName:   Windows 10 Pro
  3. ReleaseId:     1903
  4. CurrentBuild:  18362
  5. UBR:           356
  6. BuildLabEx:    18362.1.amd64fre.19h1_release.190318-1202
Is there also an API Call for this?

jamie

  • Hero Member
  • *****
  • Posts: 4679
Re: Getting System Information from the Windows Registry
« Reply #8 on: October 08, 2019, 11:39:58 pm »
GetVersionEx(LpOpVersionInfo) is generally a good start.
The only true wisdom is knowing you know nothing

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1129
    • Lebeau Software
Re: Getting System Information from the Windows Registry
« Reply #9 on: October 09, 2019, 01:12:51 am »
GetVersionEx(LpOpVersionInfo) is generally a good start.

Except that GetVersionEx() lies on Windows 8.1+, as it is now subject to the OS compatibility settings of the app's manifest (as is VerifyVersionInfo() on Windows 10+).  You can get more accurate info from RtlGetVersion() instead, which is not (yet?) subject to manifestation.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

440bx

  • Hero Member
  • *****
  • Posts: 2933
Re: Getting System Information from the Windows Registry
« Reply #10 on: October 09, 2019, 01:57:52 am »
You can get more accurate info from RtlGetVersion() instead, which is not (yet?) subject to manifestation.
And even that does not seem to be fully reliable.  It seems the only way to get the true version of Windows is by using the undocumented API "RtlGetNtVersionNumbers".

Geoff Chappell has a nice writeup on that function located at http://www.geoffchappell.com/studies/windows/win32/ntdll/api/ldrinit/getntversionnumbers.htm
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1129
    • Lebeau Software
Re: Getting System Information from the Windows Registry
« Reply #11 on: October 09, 2019, 02:32:00 am »
And even that does not seem to be fully reliable.

How so?  It has worked fine for me whenever I have used it.

It seems the only way to get the true version of Windows is by using the undocumented API "RtlGetNtVersionNumbers".

Never heard of it.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

440bx

  • Hero Member
  • *****
  • Posts: 2933
Re: Getting System Information from the Windows Registry
« Reply #12 on: October 09, 2019, 03:49:56 am »
How so?  It has worked fine for me whenever I have used it.
I wish I could answer your question precisely, I cannot but, the reason I have some doubts about that function is because MSVCRT.DLL uses the undocumented "RtlGetNtVersionNumbers" instead of "RtlGetVersion", there is probably a good reason for that, otherwise it could simply use the documented function.  I suspect that there are occasions, possibly rare, when RtlGetVersion may choose to lie to the caller.

Never heard of it.
That's why I included the link to Geoff Chappell's article on it.  Being undocumented, it is not a very well known, much less used, function.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4303
  • Compiler Developer
Re: Getting System Information from the Windows Registry
« Reply #13 on: October 09, 2019, 09:04:55 am »
GetVersionEx(LpOpVersionInfo) is generally a good start.

Except that GetVersionEx() lies on Windows 8.1+, as it is now subject to the OS compatibility settings of the app's manifest (as is VerifyVersionInfo() on Windows 10+).  You can get more accurate info from RtlGetVersion() instead, which is not (yet?) subject to manifestation.
Alternatively you can simply adjust your application's manifest...

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1129
    • Lebeau Software
Re: Getting System Information from the Windows Registry
« Reply #14 on: October 09, 2019, 07:11:31 pm »
the reason I have some doubts about that function is because MSVCRT.DLL uses the undocumented "RtlGetNtVersionNumbers" instead of "RtlGetVersion", there is probably a good reason for that, otherwise it could simply use the documented function.

I suspect it is probably more of just a dependency issue, since RtlGetVersion() and RtlGetNtVersionNumbers() are in different libraries.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018