RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//打开注册表子项
key.SetValue(程序的名称, 程序的路径);

WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);
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(@"\") + );
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);
lbl_autorunerr.Visible = false;
}
catch
{
lbl_autorunerr.Visible = true;
//throw new Exception(ex.ToString());
}
finally
{
if (reg != null)
reg.Close();
}
}

最新文章

  1. Linux安全基础:配置network
  2. LINQ的First与FirstOrDefault方法和Last与LastOrDefault方法。
  3. oss cmd
  4. [C#]集合已修改;可能无法执行枚举操作
  5. win7下IIS配置MVC项目
  6. Android改变了PDA市场格局
  7. 安卓模拟器"bluestacks"在电脑上的设置.(宽,高)
  8. NuGet的使用和服务搭建
  9. C++编写ATM(1)
  10. This manual page is part of Xcode Tools version 5.0
  11. c#中反射
  12. Python中的引号用法总结
  13. java实现发送邮件服务器,SMTP协议发送邮件
  14. VMware虚拟机下安装CentOS6.5
  15. (转)MERGE语法详解
  16. Vue.js 入门教程
  17. SQLServer 表连接种类
  18. Java接口简单理解
  19. MySQL MHA 搭建&测试(环境:CentOS7 + MySQL5.7.23)
  20. mysql 查看mysql相关信息

热门文章

  1. 使用ConcurrentLinkedQueue惨痛的教训
  2. BZOJ 3698 XWW的难题:有上下界的最大流
  3. python学习笔记(threading多线程)
  4. 转:session和cookie以及catch三者的区别
  5. 【牛客练习赛12-B】迷宫(BFS)
  6. web前端概念摘要(一)
  7. Node大文件处理
  8. ROS中使用ABB Yumi IRB14000的一些资料汇总
  9. 学习nodejs部分基础内容入门小结
  10. let防止变量声明提前