IntPtr handle = new IntPtr(-2147483646); // HKEY_LOCAL_MACHINE using (RegistryKey key = RegistryKey.FromHandle(new Microsoft.Win32.SafeHandles.SafeRegistryHandle(handle, true))) { string value = (string) key.GetValue("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName"); Console.WriteLine("Product Name: " + value); }
IntPtr handle = SomeMethodThatReturnsARegistryKeyHandle(); using (RegistryKey key = RegistryKey.FromHandle(new Microsoft.Win32.SafeHandles.SafeRegistryHandle(handle, true))) { // Use the key object here }The RegistryKey class is part of the .NET Framework's Microsoft.Win32 namespace.