C#实现开机自动启动设置代码分享
作者:junjie 时间:2021-10-08 20:45:14
/// <summary>
/// 设置程序开机启动
/// 或取消开机启动
/// </summary>
/// <param name="started">设置开机启动,或者取消开机启动</param>
/// <param name="exeName">注册表中程序的名字</param>
/// <param name="path">开机启动的程序路径</param>
/// <returns>开启或则停用是否成功</returns>
public static bool runWhenStart(bool started, string exeName, string path)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//打开注册表子项
if (key == null)//如果该项不存在的话,则创建该子项
{
key = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
if (started == true)
{
try
{
key.SetValue(exeName, path);//设置为开机启动
key.Close();
}
catch
{
return false;
}
}
else
{
try
{
key.DeleteValue(exeName);//取消开机启动
key.Close();
}
catch
{
return false;
}
}
return true;
}
标签:C#,开机,自动,启动
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot+JWT实现注册、登录、状态续签流程分析
2022-09-29 09:07:11
![](https://img.aspxhome.com/file/2023/4/71924_0s.png)
使用Deflate算法对文件进行压缩与解压缩的方法详解
2022-01-27 09:48:49
Jenkins Host key verification failed问题解决
2021-07-14 12:53:41
Android实现带指示器的自动轮播式ViewPager
2022-07-25 22:28:49
![](https://img.aspxhome.com/file/2023/2/97852_0s.gif)
android panellistview 圆角实现代码
2022-09-03 17:34:19
![](https://img.aspxhome.com/file/2023/1/98691_0s.png)
Base64编码解码原理及C#编程实例
2022-05-07 03:58:53
![](https://img.aspxhome.com/file/2023/8/70438_0s.png)
IDEA JeeSite框架httpSession.invalidate()无效问题解决方案
2023-09-23 19:44:24
java打印指定年月的日历
2023-11-11 19:21:19
![](https://img.aspxhome.com/file/2023/2/59062_0s.jpg)
Java俄罗斯方块小游戏
2021-12-01 04:36:49
![](https://img.aspxhome.com/file/2023/1/65581_0s.png)
springboot 动态数据源的实现方法(Mybatis+Druid)
2021-07-26 04:27:00
![](https://img.aspxhome.com/file/2023/8/68188_0s.png)
退出Android程序时清除所有activity的实现方法
2021-10-09 23:49:30
Android实现指针刻度转盘
2022-06-08 07:41:42
![](https://img.aspxhome.com/file/2023/0/120150_0s.jpg)
SpringBoot整合Thymeleaf小项目及详细流程
2021-08-13 16:32:08
![](https://img.aspxhome.com/file/2023/0/80890_0s.png)
SpringBoot @PropertySource与@ImportResource有什么区别
2023-08-22 02:02:47
Java反射之通过反射获取一个对象的方法信息(实例代码)
2021-08-07 15:14:46
![](https://img.aspxhome.com/file/2023/2/66532_0s.jpg)
Springmvc ajax跨域请求处理方法实例详解
2023-08-25 22:56:46
Android 添加TextView删除线(代码简单)
2022-05-27 16:48:47
![](https://img.aspxhome.com/file/2023/3/109213_0s.png)
Spring Boot实现JWT token自动续期的实现
2022-02-12 03:48:40
![](https://img.aspxhome.com/file/2023/7/97977_0s.jpg)
Swagger2配置方式(解决404报错)
2022-08-30 17:21:13
![](https://img.aspxhome.com/file/2023/0/63660_0s.png)
详解idea maven nexus 常见命令配置
2021-06-07 18:29:03
![](https://img.aspxhome.com/file/2023/1/62731_0s.png)