c# 开机启动项的小例子
时间:2022-11-30 02:16:43
//路径, 添加开机启动/删除开机启动
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();
}
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java与微信小程序实现websocket长连接
![](https://img.aspxhome.com/file/2023/5/128815_0s.jpg)
关于Unity C# Mathf.Abs()取绝对值性能测试详解
![](https://img.aspxhome.com/file/2023/7/116427_0s.jpg)
SpringBoot整合SpringTask实现定时任务的流程
Android实现文件解压带进度条功能
Java设计模式之命令模式_动力节点Java学院整理
![](https://img.aspxhome.com/file/2023/3/69913_0s.png)
解析Android框架之Volley源码
![](https://img.aspxhome.com/file/2023/9/109179_0s.png)
java使用listIterator逆序arraylist示例分享
![](https://img.aspxhome.com/file/2023/4/104004_0s.jpg)
在Spring Boot中使用Spring-data-jpa实现分页查询
![](https://img.aspxhome.com/file/2023/5/89595_0s.png)
java 二叉查找树实例代码
基于Java中字符串indexof() 的使用方法
![](https://img.aspxhome.com/file/2023/7/65587_0s.jpg)
常见Android选项菜单样式集合
![](https://img.aspxhome.com/file/2023/2/114282_0s.png)
SpringBoot整合OpenCV的实现示例
![](https://img.aspxhome.com/file/2023/2/132192_0s.jpg)
Android编程中关于单线程模型的理解与分析
SpringBoot中属性赋值操作的实现
![](https://img.aspxhome.com/file/2023/3/70943_0s.png)
AndroidStudio简单实现BMI计算
![](https://img.aspxhome.com/file/2023/5/139535_0s.jpg)
java生成XML的方法
WPF+SkiaSharp实现自绘弹幕效果
![](https://img.aspxhome.com/file/2023/6/98186_0s.gif)
Kotlin基础教程之面向对象
![](https://img.aspxhome.com/file/2023/3/78973_0s.png)
Java实现map转换成json的方法详解
IDEA解决src和resource下创建多级目录的操作
![](https://img.aspxhome.com/file/2023/0/63690_0s.jpg)