I just discovered that the reason my code for detecting and changing key values wasn't working, was because it WAS working - just on a different user. Because my winform app will need elevated access for some operations, I have the following in my manifest per many guides saying this is necessary:
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Meanwhile, I have code for detecting and changing a value in the registry as follows:
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64))
using (var F1key = hklm.OpenSubKey(@"SOFTWARE\Classes\TypeLib\{8cec5860-07a1-11d9-b15e-000d56bfe6ee}\1.0\0\win64"))
{
// EGADS! It's active!
if (F1key != null)
{
fckF1Status.Text = "F1 Help is on. Turning off";
F1key.SetValue("", "", RegistryValueKind.String);
}
else
{
fckF1Status.Text = "F1 Help is off. Turning on";
F1key.SetValue("", "c:\windows\helppane.exe", RegistryValueKind.String);
}
}
The problem is that the changes only show up when I'm looking at regedit as an admin and it appears to be loading it into the "current user" branch of the admin and not the logged in user. How can I make sure registry changes to Registry.CurrentUser are for the logged in user and not the admin/elevated account?