C#如何判断注册表是否已存在

C#如何判断注册表是否已存在,如果以存在则运行aaa.exe,如果不存在则提示“某某文件不存在”,这个要怎么做呀,
注册码:"exepath"="C:\\Program Files\\StormII\\Storm.exe"
或者是直接判断Storm这个文件夹存在或不存在。

哪位大虾给个代码呀,本人新手,代码最好加注释,谢谢啊。
简单一些,直接判断注册表里的Storm这个文件夹存在或不存在。如果存在就直接运行(某某)程序,如果不存在则提示(某)文件不存在,谢谢啊,给注释。

是用按钮来操作的

给你一个去注册表里面的内容的例子
private string GetRegistData(string name)
{
string registData;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE",true);
RegistryKey aimdir = software.OpenSubKey("XXX",true);
registData = aimdir.GetValue(name).ToString();
return registData;
}

如果为空的话,就表示不存在

ps
你在按钮添加一个事件,把这个事件绑定到这个方法不行吗?
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-12-25
读写注册表的类
using Microsoft.Win32;

参考下吧

public static bool InitEPath()
{
RegistryKey pregkey;
try
{
pregkey = Registry.LocalMachine.OpenSubKey("SYSTEM", true).OpenSubKey("ControlSet001", true).OpenSubKey("Control", true).OpenSubKey("Session Manager", true).OpenSubKey("Environment", true);

if (null != pregkey)
{
if (null == pregkey.GetValue(keys))
{
pregkey.SetValue(keys, "TRUE");
pregkey.Close();
return true;
}
}
}
catch
{

}
return false;
}

Registry.LocalMachine 打开注册表中的 HKEY_LOCAL_MACHINE ,
OpenSubKey("SYSTEM", true). 打开HKEY_LOCAL_MACHINE 中的SYSTEM项,然后下面的项是一个一个下去的。本回答被提问者采纳