How to check if a registry value exists by C# code? This is my code, I want to check if 'Start' exists.
public static bool checkMachineType()
{
RegistryKey winLogonKey = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\services\pcmcia", true);
string currentKey= winLogonKey.GetValue("Start").ToString();
if (currentKey == "0")
return (false);
return (true);
}
For Registry Key you can check if it is null after getting it. It will be, if it doesn't exist.
For Registry Value you can get names of Values for the current key and check if this array contains the needed Value name.
Example:
public static bool checkMachineType()
{
RegistryKey winLogonKey = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\services\pcmcia", true);
return (winLogonKey.GetValueNames().Contains("Start"));
}