Jump to content

C# Help getting values from the registry

AlTech
Go to solution Solved by AlTech,

@vorticalbox So I found the issue xD. I'm a little embarrassed.

 

The issue was a typo...........

 

edition = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "EditionID", "Windows version not detected");
            buildBranch = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "BuildBranch", "Windows build branch not detected");
            CurrentBuild = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuildNumber", "Windows build number not detected");
            productName = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", "Windows product name not detected");
            release = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ReleaseID", "Windows release not detected");
            productID = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductID", "Windows product ID not detected");
            owner = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "RegisteredOwner", "Windows owner not detected");           [/Code]

Hi guys,

I'm trying to get information from the registry and I can't seem to do so............

 

Here's the relevant code:

        object edition;
        object buildBranch;
        object CurrentBuild;
        object productName;
        object release;
        object productID;
        object owner;

  edition = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Windows NT\\CurrentVersion", "EditionID", "Windows version not detected");
            buildBranch = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Windows NT\\CurrentVersion", "BuildBranch", "Windows build branch not detected");
            CurrentBuild = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Windows NT\\CurrentVersion", "CurrentBuildNumber", "Windows build number not detected");
            productName = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Windows NT\\CurrentVersion", "ProductName", "Windows product name not detected");
            release = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Windows NT\\CurrentVersion", "ReleaseID", "Windows release not detected");
            productID = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Windows NT\\CurrentVersion", "ProductID", "Windows product ID not detected");
            owner = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Windows NT\\CurrentVersion", "RegisteredOwner", "Windows owner not detected");         



releaseVersion.Text = Convert.ToString(release);
            osbuild.Text = Convert.ToString(CurrentBuild);
            releaseVersion.Text = Convert.ToString(release);
            branch.Text = Convert.ToString(buildBranch);
            ownerBox.Text = Convert.ToString(owner);

Thanks a bunch :).

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

try

 

using (Microsoft.Win32.RegistryKey key = 
       Microsoft.Win32.Registry.LocalMachine
               .OpenSubKey(@"SOFTWARE\Microsoft\WindowsNT\CurrentVersion"))
{
    var osVersion = key.GetValue("CurrentVersion");
}

You can also use Environment.OSVersion

 

Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, vorticalbox said:

try

 


using (Microsoft.Win32.RegistryKey key = 
       Microsoft.Win32.Registry.LocalMachine
               .OpenSubKey(@"SOFTWARE\Microsoft\WindowsNT\CurrentVersion"))
{
    var osVersion = key.GetValue("CurrentVersion");
}

You can also use Environment.OSVersion

 


Console.WriteLine("OSVersion: {0}", Environment.OSVersion.ToString());

 

environment.osversion doesn't return the correct value under Windows 10. It says 6.3 instead of 10.0

 

I'll try what you suggested when I'm at my desktop

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, AluminiumTech said:

environment.osversion doesn't return the correct value under Windows 10. It says 6.3 instead of 10.0

 

ill tty what you suggested when I'm at my desktop

https://msdn.microsoft.com/en-gb/library/windows/desktop/ms724832(v=vs.85).aspx?f=255&MSPPError=-2147217396

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

39 minutes ago, vorticalbox said:

* For applications that have been manifested for Windows 8.1 or Windows 10. Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

@vorticalbox So I found the issue xD. I'm a little embarrassed.

 

The issue was a typo...........

 

edition = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "EditionID", "Windows version not detected");
            buildBranch = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "BuildBranch", "Windows build branch not detected");
            CurrentBuild = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuildNumber", "Windows build number not detected");
            productName = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", "Windows product name not detected");
            release = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ReleaseID", "Windows release not detected");
            productID = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductID", "Windows product ID not detected");
            owner = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "RegisteredOwner", "Windows owner not detected");           [/Code]

Judge a product on its own merits AND the company that made it.

How to setup MSI Afterburner OSD | How to make your AMD Radeon GPU more efficient with Radeon Chill | (Probably) Why LMG Merch shipping to the EU is expensive

Oneplus 6 (Early 2023 to present) | HP Envy 15" x360 R7 5700U (Mid 2021 to present) | Steam Deck (Late 2022 to present)

 

Mid 2023 AlTech Desktop Refresh - AMD R7 5800X (Mid 2023), XFX Radeon RX 6700XT MBA (Mid 2021), MSI X370 Gaming Pro Carbon (Early 2018), 32GB DDR4-3200 (16GB x2) (Mid 2022

Noctua NH-D15 (Early 2021), Corsair MP510 1.92TB NVMe SSD (Mid 2020), beQuiet Pure Wings 2 140mm x2 & 120mm x1 (Mid 2023),

Link to comment
Share on other sites

Link to post
Share on other sites

17 minutes ago, AluminiumTech said:

 

 

I know thats why i sent you there so you can target your applications :P 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×