c#检测注册表,请高手指点~~

来源:百度知道 编辑:UC知道 时间:2024/06/17 12:58:20
程序检测注册表:HKEY_LOCAL_MACHINE\SOFTWARE\CardScan的ScanExe项,如果不存在或者值不是当前程序所在路径,则创建或者修改为当前路径(全路径);

求救~~
本人之前没做过关于注册表的程序,请高手指点一下~~~急啊!!!!!!

Microsoft.Win32.RegistryKey pregkey;
pregkey = Registry.LocalMachine.OpenSubKey("SOFTWARE", true).OpenSubKey("CardScan", true);
if (null != pregkey)
{
if (null == pregkey.GetValue(keys))
{
pregkey.SetValue(keys, "TRUE");
pregkey.Close();
return true;
}
}

using Microsoft.Win32;

代码:

string currentExePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
RegistryKey key = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\CardScan", RegistryKeyPermissionCheck.ReadWriteSubTree );
if ( key == null ) key = Registry.LocalMachine.CreateSubKey( @"SOFTWARE\CardScan", RegistryKeyPermissionCheck.ReadWriteSubTree );
string v = key.GetValue( "ScanExe", string.Empty ).ToString();
if ( string.IsNullOrEmpty( v ) || v != currentExePath )