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

论坛 期权论坛 脚本     
niminba   2021-5-16 09:45   12   0

本文实例讲述了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);
   }
  }
 }
}

希望本文所述对大家的C#程序设计有所帮助。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP