软件编程
位置:首页>> 软件编程>> C#编程>> C#实现将应用程序设置为开机启动的方法

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

作者:我心依旧  发布时间:2023-06-04 05:59:26 

标签: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);
  }
 }
}
}

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

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com