c#Winform程序,如何在 win7⼀8 64位电脑上设置开机自动启动

如题,请大神帮忙。用下面这个写的,添加注册表成功了,但是开机没有启动,360也检测不到启动项。string path = Application.ExecutablePath;RegistryKey rk2 = baseNode.CreateSubKey(@"Software尀Microsoft尀Windows尀CurrentVersion尀Run");rk2.SetValue("***", path);
2026年09月20日 10:10
有2个网友回答
网友(1):

///


/// 设置自动启动
///

/// 文件名
/// 是否自动启动
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();
}
}

网友(2):

C#/WPF程序实现软件开机自动启动的两种常用方法 - CSDN博客 https://blog.csdn.net/liyu3519/article/details/81257839