WillingMost7
WillingMost7

Reputation: 55

Can't read Registry value with C#

I'm having a bit trouble. I'm doing a Programming-Project from school and I need to read all of the system info from the Registry using C#. Now I'm using Microsoft.Win32 to access the Register, but I don't know where I can find all of the needed info (I've found CPU, GPU, MB and BIOS, but where can I find more usefull data? Like connected drives or amount of RAM and etc..)

Also, I can't present the GPU name for some reason. Here is the code (I'm using WinForm):

string gpu = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinSAT", "PrimaryAdapterString", null);
txtGPU.Text = "Your GPU is: " + gpu;

But for some reason it does not present (I see only the text "Your GPU is", but without the name of the GPU. I used the same trick to show the CPU name and it worked).

And one last thing, inside the HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor there are folders as the amount of logical cores. How can I count the folders to present the amount of the logical cores?

Thanks for all helpers! Sorry for being a newbie..

Upvotes: 1

Views: 2489

Answers (1)

Przetczak
Przetczak

Reputation: 131

Try this. You have null because in default VS reading 32x registry. You need set to 64x.

string subkey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinSAT";
    
RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
string value = localKey.OpenSubKey(subkey).GetValue("PrimaryAdapterString").ToString();

Upvotes: 3

Related Questions