C#怎么让程序开机启动,我是要电脑一开机就执行,不要点击什么按钮或者打开其他程序设计什么
privatevoidForm1_Load(objectsender,EventArgse){RegisterClassrg=newRegisterClass();rg....
private void Form1_Load(object sender, EventArgs e)
{
RegisterClass rg = new RegisterClass();
rg.start_with_windows();
}
namespace AutoClass
{
class RegisterClass
{
///<summary>
///开机启动注册标检查
///</summary>
public void start_with_windows()
{
RegistryKey registryKey = Registry.LocalMachine;
RegistryKey run = registryKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);
if (run == null)
{
register();
}
}
private void register()
{
string starupPath = Application.ExecutablePath;
RegistryKey loca = Registry.LocalMachine;
string name = Path.GetFileName(starupPath);
RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
try
{
run.SetValue(name, starupPath);
loca.Close();
run.Close();
}
catch (Exception)
{
}
} 展开
{
RegisterClass rg = new RegisterClass();
rg.start_with_windows();
}
namespace AutoClass
{
class RegisterClass
{
///<summary>
///开机启动注册标检查
///</summary>
public void start_with_windows()
{
RegistryKey registryKey = Registry.LocalMachine;
RegistryKey run = registryKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);
if (run == null)
{
register();
}
}
private void register()
{
string starupPath = Application.ExecutablePath;
RegistryKey loca = Registry.LocalMachine;
string name = Path.GetFileName(starupPath);
RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
try
{
run.SetValue(name, starupPath);
loca.Close();
run.Close();
}
catch (Exception)
{
}
} 展开
3个回答
展开全部
直接将快捷方式发送到C:\Users\userName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 下呢?
C# 创建快捷方式方法参考:http://blog.csdn.net/testcs_dn/article/details/8674265
C# 创建快捷方式方法参考:http://blog.csdn.net/testcs_dn/article/details/8674265
更多追问追答
追问
我直接把快捷方式放在开始启动里面都不行了
追答
那下面链接的这篇博文不知你看了没有:
http://www.cnblogs.com/wang7/archive/2012/06/04/2535019.html
展开全部
写服务,或者是计划任务。或者写启动脚本,总之很多办法。
追问
搞定,谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
C#/WPF程序实现软件开机自动启动的两种常用方法 - CSDN博客 https://blog.csdn.net/liyu3519/article/details/81257839
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询