c#Winform程序,如何在 win7/8 64位电脑上设置开机自动启动
发布网友
发布时间:2022-05-11 17:15
我来回答
共2个回答
热心网友
时间:2023-11-04 03:58
/// <summary>
/// 设置自动启动
/// </summary>
/// <param name="sFileName">文件名</param>
/// <param name="blIsAutoRun">是否自动启动</param>
private void SetAutoRun(string sFileName, bool blIsAutoRun)
{
RegistryKey reg = null;
try
{
if (!System.IO.File.Exists(sFileName))
return;
String name = sFileName.Substring(sFileName.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 (reg == null)
return;
if (blIsAutoRun)
reg.SetValue(name, sFileName);
else
reg.SetValue(name, false);
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
finally
{
if (reg != null)
reg.Close();
}
}追问我用这个添加了注册表,也添加成功了,但是开机启动不了,360里也没有启动项
追答注册到CurrentUser的相同目录下试试
热心网友
时间:2023-11-04 03:59
C#/WPF程序实现软件开机自动启动的两种常用方法 - CSDN博客 https://blog.csdn.net/liyu3519/article/details/81257839