前端开发入门到精通的在线学习网站

网站首页 > 资源文章 正文

C#实现exe程序开机自动启动(c# 开机运行)

qiguaw 2025-02-04 15:44:45 资源文章 21 ℃ 0 评论

一、配置文件

<!--是否开机启动 TRUE 启动 FALSE 禁止-->  
<add key="IsBoot" value="FALSE"/>

二、代码实现

if (ConfigurationManager.AppSettings["IsBoot"].ToString().Trim().ToUpper() == "TRUE")
{
	//设置开机启动
	string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
	RegistryKey rk = Registry.LocalMachine;
	RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
	rk2.SetValue("JcShutdown", path);
	rk2.Close();
	rk.Close();
}
else
{
	string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
	RegistryKey rk = Registry.LocalMachine;
	RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
	rk2.DeleteValue("JcShutdown", false);
	rk2.Close();
	rk.Close();
}

C#实现exe程序开机自动启动

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表