How to check if a registry value exists using C#?

后端 未结 7 1531
庸人自扰
庸人自扰 2020-12-08 13:28

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()
{
    Registr         


        
7条回答
  •  借酒劲吻你
    2020-12-08 13:32

    string keyName=@"HKEY_LOCAL_MACHINE\System\CurrentControlSet\services\pcmcia";
    string valueName="Start";
    if (Registry.GetValue(keyName, valueName, null) == null)
    {
         //code if key Not Exist
    }
    else
    {
         //code if key Exist
    }
    

提交回复
热议问题