因此,在我的注册表中,我在"LocalMachine\SOFTWARE\Microsoft\Windows\CurrentVersion\Run \"下输入名为"COMODO Internet Security"的条目,这是我的防火墙.现在我想知道的是如何让注册表检查该条目是否存在?如果它确实如此,那么这样做.我知道如何检查子项"Run"是否存在但不是"COMODO Internet Security"的条目,这是我用来获取子密钥的代码.
using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"))
if (Key != null)
{
MessageBox.Show("found");
}
else
{
MessageBox.Show("not found");
}
Run Code Online (Sandbox Code Playgroud)
如果您正在寻找子项下的值,(您的意思是"条目"?),您可以使用RegistryKey.GetValue(string).这将返回值(如果存在),如果不存在则返回null.
例如:
using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"))
if (Key != null)
{
string val = Key.GetValue("COMODO Internet Security");
if (val == null)
{
MessageBox.Show("value not found");
}
else
{
// use the value
}
}
else
{
MessageBox.Show("key not found");
}
Run Code Online (Sandbox Code Playgroud)