RunWhenStart(false, Application.ProductName, Application.StartupPath + @"\ToolsByJack.exe");
///
/// 开机启动项
///
/// 是否启动
/// 启动值的名称
/// 启动程序的路径
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)
{
System.Windows.Forms.MessageBox.Show(err.Message, "ToolsByJack", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); }
} else
{
try
{
if (Run.GetValue(name) != null)
{
Run.DeleteKey(name,false);
HKLM.Close();
} }
catch (Exception)
{
//
}
}
}
c#开机自动启动程序实现代码
1.放到启动文件夹
2.添加注册表的run值
3.为C#程序编写一个服务,通过服务调用
4.DLL插入进程explorer,进行调用
做成winservice