I've been trying to test the value
of a registry key, with no success. I tried a lot of suggestions but to no success. What am I missing?
Problem: this code always returns false for value = 0 AND value = 1 (while the actual value in registry is 0
- as seen in the screenshot below).
using Microsoft.Win32;
string rpath = @"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\";
string rkey = "EnableLUA";
object value = "0";
if ((Registry.GetValue(rpath, rkey, value) == value))
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}
// public static object? GetValue (string keyName, string? valueName, object? defaultValue);
// https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.registry.getvalue?view=net-5.0
I'm using C# in Visual Studio 2019 and .NET 5.0