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