C#设置软件开机自启动

通过C#操作注册表来实现。

直接调用方法。

private void AutoStart(bool isAuto = true)       
 {            
	 if (isAuto == true)            
	 {               
		RegistryKey local = Registry.CurrentUser;               
		RegistryKey run = local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");                
		run.SetValue("ProName", System.Windows.Forms.Application.ExecutablePath);                
		run.Close();                
		local.Close();            
	   }           
	else           
	{                
		RegistryKey local = Registry.CurrentUser;               
		RegistryKey run = local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");                
		run.DeleteValue("ProName", false);                
		run.Close();               
		local.Close();           
 	 }        
}

你可能感兴趣的:(C#,c#,.net,笔记)