本文实例讲述了C#实现程序开机启动的方法。分享给大家供大家参考,具体如下:
//此方法把启动项加载到注册表中//获得应用程序路径string strAssName = Application.StartupPath + @"/" + Application.ProductName + @".exe";//获得应用程序名string ShortFileName = Application.ProductName;RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run", true);if (rgkRun == null){ rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run");}rgkRun.SetValue(ShortFileName, strAssName);//此删除注册表中启动项//获得应用程序名string ShortFileName = Application.ProductName;RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run", true);if (rgkRun == null){ rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run");}rgkRun.DeleteValue(ShortFileName, false);
更多关于C#相关内容感兴趣的读者可查看本站专题:《C#常见控件用法教程》、《C#数据结构与算法教程》、《C#面向对象程序设计入门教程》及《C#程序设计之线程使用技巧总结》
希望本文所述对大家C#程序设计有所帮助。
新闻热点
疑难解答