I am trying to validate the registry keys my WinForms app with VS2019(.Net 4.7.2). I have tried all the solutions out there(but nothing worked) for the same issue such as,
(a). Setting the Application build to AnyCPU/x64/x86
(b). Unchecking the Prefe 32-bit checkbox.
(c). Running my VS as an Admin.
(d). Checked the permissions of the key and its accessible to Everyone with Full Control enabled.
string var1 = Environment.UserDomainName + "\\" + Environment.UserName;
using(RegistryKey localMachine = Environment.Is64BitProcess ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) : Registry.LocalMachine) {
var key = localMachine.OpenSubKey("Computer\\HKEY_LOCAL_MACHINE");
}
using(RegistryKey registry = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64).OpenSubKey("Computer\\HKEY_LOCAL_MACHINE")) {
}
using(RegistryKey key = Registry.LocalMachine.OpenSubKey("Computer\\HKEY_LOCAL_MACHINE")) {
if (key != null) {
}
}
Tried all the variations to read the directory, but not working.
Is it because of the Domain and Username? Environment.UserDomainName gives my company Domain and Environment.UserName gives the username I logged into my computer.
Can some one help me what or where I need to change to get the keys?