Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading value from registry

Tags:

c#

.net

registry

google is not helping me today, so i need your help. Is there a possible way to read a value from a registry ? example this location --> HKEY_LOCAL_MACHINE > SOFTWARE > MyKey the column is Test key

like image 255
Tiriman Chokshanada Avatar asked May 03 '26 16:05

Tiriman Chokshanada


1 Answers

64bit + 32bit

   using Microsoft.Win32;
    public static string GetRegistry()
    {
        string registryValue = string.Empty;
        RegistryKey localKey = null;
        if (Environment.Is64BitOperatingSystem)
        {
            localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
        }
        else
        {
            localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
        }

        try
        {
            localKey = localKey.OpenSubKey(@"Software\\MyKey");
            registryValue = localKey.GetValue("TestKey").ToString();
        }
        catch (NullReferenceException nre)
        {

        }
        return registryValue;
    }
like image 199
Harminder Avatar answered May 06 '26 06:05

Harminder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!