C#实现将应用程序设置为开机启动的方法

 C#实现将应用程序设置为开机启动的方法
作者:我心依旧
这篇文章主要介绍了C#实现将应用程序设置为开机启动的方法,涉及C#针对注册表的写入技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了C#实现将应用程序设置为开机启动的方法。分享给大家供大家参考。具体如下:
private void WriteRegistry()
{
 string strName = Application.ExecutablePath;
 if (File.Exists(strName))
 {
  string strNewName = Path.GetFileName(strName);
  RegistryKey reg = Registry.LocalMachine.OpenSubKey("SOFTWARE \\Microsoft\\Windows\\CurrentVersion\\Run", true);
  if (reg == null)
  {
   reg = Registry.LocalMachine.CreateSubKey("SOFTWARE \\Microsoft\\Windows\\CurrentVersion\\Run");
  }
  else
  {
   if (reg.GetValue(strNewName) == null)
   {
    reg.SetValue(strNewName, strName);
   }
  }
 }
}

你可能感兴趣的:(WPF,C#)