C# 设置/取消程序 开机自启动

(修改注册表)
【设置开机自启动】
复制代码
using Microsoft.Win32;//添加命名空间

public static bool SetAutoRun(string keyName,string filePath) { try { RegistryKey runKey=Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun",true); runKey.SetValue(keyName,filePath); runKey.Close(); } catch { return false; } return true; }
复制代码

【取消开机自启动】

复制代码
using Microsoft.Win32;//添加命名空间

public static bool DeleteAutoRun(string keyName,string filePath) { try { RegistryKey runKey=Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionRun",true); runKey.DeleteValue(keyName,filePath); runKey.Close(); } catch { return false; } return true; }
另外一种方式,将对应的应用,或者应用的快捷方式放置在开始文件列表中。
原文地址:https://www.cnblogs.com/Yellow0-0River/p/4453150.html