C#编写的windows程序随系统启动
生活随笔
收集整理的這篇文章主要介紹了
C#编写的windows程序随系统启动
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
url:http://www.cnblogs.com/emanlee/archive/2009/08/31/1557380.html
設置某程序隨系統啟動自動運行,取消自動運行。 使用到using Microsoft.Win32;名稱空間。
public 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); MessageBox.Show("設定成功!","提示"); } catch { //throw new Exception(ex.ToString()); } finally { if (reg != null) reg.Close(); } }?
?
轉載于:https://www.cnblogs.com/haight/p/3292713.html
總結
以上是生活随笔為你收集整理的C#编写的windows程序随系统启动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 微信分享没反应问题总结
- 下一篇: c# char unsigned_dll