永发信息网

怎么让一个用C#写的程序,开机时自动运行

答案:2  悬赏:40  手机版
解决时间 2021-02-15 17:39
  • 提问者网友:鼻尖触碰
  • 2021-02-15 02:29
怎么让一个用C#写的程序,开机时自动运行
最佳答案
  • 五星知识达人网友:廢物販賣機
  • 2021-02-15 03:34
将你编译好的exe文件放到startup中,一下是startup文件位置
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
//------------------------------------------------------------------------------------------------
【注册表】
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\explorer\User Shell Folders]
  \ "Common Startup\ "=\ "%Directory%\ "
  [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\explorer\Shell Folders]
  \ "Common Startup\ "=\ "%Directory%\ "
//------------------------------------------------------------------------------------------------

C:\Users\用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
//------------------------------------------------------------------------------------------------
【注册表】
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]
  Startup=\ "%Directory%\ "
  [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]
  Startup=\ "%Directory%\ "
//------------------------------------------------------------------------------------------------
全部回答
  • 1楼网友:一袍清酒付
  • 2021-02-15 04:11
/// /// 设置应用程序开机自动运行 /// /// 应用程序的文件名 /// 是否自动运行,为false时,取消自动运行 /// 设置不成功时抛出异常 public static void setautorun(string filename,bool isautorun) { registrykey reg=null; try { if (!system.io.file.exists(filename)) throw new exception("该文件不存在!"); string name = filename.substring(filename.lastindexof("\") + 1); reg = registry.localmachine.opensubkey("software\microsoft\windows\currentversion\run", true); if (reg == null) reg = registry.localmachine.createsubkey("software\microsoft\windows\currentversion\run"); if (isautorun) reg.setvalue(name, filename); else reg.setvalue(name, false); } catch (exception ex) { throw new exception(ex.tostring()); } finally { if(reg!=null) reg.close(); } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯