I am trying to get values and set values to the Registry .
When I am trying to access a path that not located at the registry I am getting exception.
But when I am setting that path with Registry.SetValue(keyName, "", 0);, all works fine and I can get non existing values from it.
Any idea why I can’t use my public int GetComponent(string RegKey) function on nun existing paths?
public class LP_Registery
{
private const string userRoot = "HKEY_CURRENT_USER";
private const string subkey = @"Software\PCBMatrix\LPWizard";
private string keyName;
public LP_Registery(string folderName) => keyName = userRoot + "\\" + subkey + "\\" + folderName;
public int GetComponent(string RegKey) => (int)Registry.GetValue(keyName, RegKey, 0);
public void SetComponent(string RegKey, int RegVal) => Registry.SetValue(keyName, RegKey, RegVal, RegistryValueKind.DWord);
}
And if it possible what should i do that it will be possible.
Thanks.
surround the GetValue with try – catch block and enjoy the coding.
Exceptions and Conditions of GetValue:
SetValue method: