注册表检查

public string result;
public string GetRegData(string regFatherPath, string Value1, string Value1Data, string Value2)
{
RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regFatherPath, false);
if (key != null)
{
foreach (string keyName in key.GetSubKeyNames())
{
try
{
RegistryKey key2 = key.OpenSubKey(keyName, false);
if (key2.GetValue(Value1).ToString() == Value1Data)
{
result = key2.GetValue(Value2).ToString();
break;
}
}
catch { MessageBox.Show(Value1Data + " or " + Value2 + " is not exist."); }

}
return result;
}
else return "Fail";
}

posted @ 2013-06-08 14:13  Ethan.Sun  阅读(135)  评论(0编辑  收藏  举报