111,071
社区成员




string strIsFirstRun = "false";
bool isFirstRun = false;
strIsFirstRun = ConfigurationManager.AppSettings("IsFirstRun");
if (string.IsNullOrEmpty(strIsFirstRun) || strIsFirstRun.ToLower() != "true")
{
isFirstRun = false;
}
else
{
isFirstRun = true;
}
strIsFirstRun = "false";
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Remove("IsFirstRun");
config.AppSettings.Settings.Add("IsFirstRun", strIsFirstRun);
config.Save();
/// <summary>
/// 写注册表中字串(REG_SZ)数据
/// </summary>
/// <param name="HKLM_SOFT_Dir_Name">HKLM\SOFTWARE的子项名称</param>
/// <param name="Sub_Dir_Name">\SOFTWARE\SOFT_Dir_Name\的子项的名称</param>
/// <param name="Key_Name">Sub_Dir_Name的子键名</param>
/// <param name="Key_Value">写入Key_Name的键值</param>
public void SetRegeditData(String HKLM_SOFT_Dir_Name, String Sub_Dir_Name, String Key_Name, String Key_Value)
{
RegistryKey hklm = Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
RegistryKey software;
if (IsRegeditDirExist(HKLM_SOFT_Dir_Name))
{
software = hklm.OpenSubKey(HKLM_SOFT_Dir_Name, true);
}
else
{
software = hklm.CreateSubKey(HKLM_SOFT_Dir_Name);
}
RegistryKey aimdir = software.CreateSubKey(Sub_Dir_Name);
aimdir.SetValue(Key_Name, Key_Value);
}
/// <summary>
/// 判断目录是否存在
/// </summary>
/// <param name="HKLM_SOFT_Dir_Name">HKLM\SOFTWARE下是否存在该子项</param>
/// <returns>true or false</returns>
public bool IsRegeditDirExist(String HKLM_SOFT_Dir_Name)
{
bool _exit = false;
string[] subkeyNames;
RegistryKey hklm = Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
subkeyNames = hklm.GetSubKeyNames();
foreach (string DirName in subkeyNames)
{
if (DirName == HKLM_SOFT_Dir_Name)
{
_exit = true;
return _exit;
}
}
return _exit;
}