c# 开机自启动代码
				
									
					
					
						|  | 
							admin 2025年10月17日 22:12
								本文热度 686 | 
					
				 
				      private static bool SetAutoStart(bool enable) {     try     {         using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))         {             if (key == null)             {                 return false;             }             if (enable)             {                 string appPath = Application.ExecutablePath;                 key.SetValue("你的软件名称", $"\"{appPath}\"");             }             else             {                 key.DeleteValue("你的软件名称", false);             }             return true;         }     }     catch (Exception ex)     {         NLogHelper.NLogHelper.Error(ex);         return false;     } }
该文章在 2025/10/18 11:27:21 编辑过