#region 开机自启动
/// <summary>
/// 是否已注册开机自启动
/// </summary>
/// <returns></returns>
private bool HasRegistry()
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
object obj = registryKey.GetValue(ProgramName);//可以自定义
return obj != null && !string.IsNullOrEmpty(obj.ToString());
}
/// <summary>
/// 注册或取消开机自启动
/// </summary>
/// <param name="reg"></param>
private void RegistryWithSystem(bool reg)
{
if (reg)
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
registryKey.SetValue(ProgramName, System.Windows.Forms.Application.ExecutablePath);
}
else
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
registryKey.DeleteValue(ProgramName);
}
}
#endregion