C#设置开机启动项、取消开机启动项
作者:junjie 时间:2023-02-19 19:40:32
如果想你写的程序随系统开机一起启动的话,那么你可以照下面这个方法来做。
RunWhenStart(false, Application.ProductName, Application.StartupPath + @\"\\MUS.exe\");
/// <summary>
/// 开机启动项
/// </summary>
/// <param name=\"Started\">是否启动</param>
/// <param name=\"name\">启动值的名称</param>
/// <param name=\"path\">启动程序的路径</param>
public static void RunWhenStart(bool Started, string name, string path)
{
RegistryKey HKLM = Registry.LocalMachine;
RegistryKey Run = HKLM.CreateSubKey(@\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");
if (Started == true)
{
try
{
Run.SetValue(name, path);
HKLM.Close();
}
catch (Exception Err)
{
MessageBox.Show(Err.Message.ToString(), \"MUS\", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} [Page]
else
{
try
{
Run.DeleteValue(name);
HKLM.Close();
}
catch (Exception)
{
//
}
}
}
标签:C#,设置,取消,开机启动项
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#使用符号表实现查找算法
2022-08-07 01:16:45
![](https://img.aspxhome.com/file/2023/8/122678_0s.jpg)
C#实现多文件压缩与解压功能
2022-03-05 04:45:54
![](https://img.aspxhome.com/file/2023/8/86978_0s.gif)
Java实现简单树结构
2023-08-06 18:59:12
SpringBoot跨域Access-Control-Allow-Origin实现解析
2023-11-28 23:04:34
手把手教你SpringBoot轻松整合Minio
2022-07-24 14:00:37
基于C语言实现井字棋游戏
2023-06-28 21:23:18
如何用C#创建用户自定义异常浅析
2023-06-10 20:06:16
java中压缩文件并下载的实例详解
2022-01-01 04:59:12
java实现马踏棋盘算法(骑士周游问题)
2022-03-17 20:29:46
![](https://img.aspxhome.com/file/2023/1/94361_0s.jpg)
浅谈SpringMVC的执行流程
2023-09-30 17:59:59
![](https://img.aspxhome.com/file/2023/8/62358_0s.png)
android studio 新建项目报错的解决之路
2022-09-20 14:24:58
java实战之飞机大战小游戏(源码加注释)
2021-08-01 17:46:08
![](https://img.aspxhome.com/file/2023/5/63485_0s.png)
Spring Boot JPA中使用@Entity和@Table的实现
2023-11-22 11:49:58
SpringCloud客户端报错:- was unable to send heartbeat!的解决
2021-08-13 14:08:11
Springboot快速入门教程
2023-03-02 21:50:56
![](https://img.aspxhome.com/file/2023/9/125319_0s.png)
Android编程中HTTP服务用法详解
2022-06-14 02:08:43
![](https://img.aspxhome.com/file/2023/1/138441_0s.png)
23种设计模式(7) java代理模式
2023-01-28 21:57:20
java中的枚举类型详细介绍
2023-06-26 22:31:26
Sprint Boot 集成MongoDB的操作方法
2022-11-13 07:10:37
Spring MVC+FastJson+Swagger集成的完整实例教程
2023-08-11 22:50:02
![](https://img.aspxhome.com/file/2023/6/86806_0s.png)