源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c# 开机启动项的小例子

  • 时间:2020-06-10 02:57 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c# 开机启动项的小例子
[u]复制代码[/u] 代码如下:
  //路径, 添加开机启动/删除开机启动         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();             }         }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部