积极答复者
怎样用代码将程序设置成开机启动项?

问题
答案
-
你好
你需要引用Microsoft.Win32命名空间。
private void RunStartup(Boolean RunOnStartup) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (RunOnStartup == true) { key.SetValue("Application Name", Application.ExecutablePath.ToString());//指定他的程序名称,获取当前程序的exe的路径 } else { key.DeleteValue("Application Name", false); } } 参数是true表示需要开机启动程序。false的话就在注册表删除。
希望对你有帮助。
Cookie Luo[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 feiyun0112Moderator 2011年6月16日 1:09
全部回复
-
你好:)
这个题目只要设置注册表就可以了(参考:http://banjoandy.blog.163.com/blog/static/1205570552011525249676/)
如果你有其它意见或私下交流,请发送邮件到:maledong@qq.com;或者请
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处 -
你好
你需要引用Microsoft.Win32命名空间。
private void RunStartup(Boolean RunOnStartup) { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (RunOnStartup == true) { key.SetValue("Application Name", Application.ExecutablePath.ToString());//指定他的程序名称,获取当前程序的exe的路径 } else { key.DeleteValue("Application Name", false); } } 参数是true表示需要开机启动程序。false的话就在注册表删除。
希望对你有帮助。
Cookie Luo[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 feiyun0112Moderator 2011年6月16日 1:09