C# winform程序开机自启动

//自启动
RegistryKey r_loca1l = Registry.CurrentUser; RegistryKey r_run1 = r_loca1l.CreateSubKey(@"software\microsoft\windows\currentversion\run"); r_run1.SetValue("exe名称", Application.ExecutablePath); r_run1.Close(); r_loca1l.Close();

//检查是否开机自启
RegistryKey r_local = Registry.LocalMachine;
RegistryKey r_run = r_local.OpenSubKey(@"software\microsoft\windows\currentversion\run", false);
if (r_run.GetValue("ServiceManageCenter") != null)
{


}
r_run.Close();
r_local.Close();

 

 

//关机命令

int time = 1; //单位为:秒
Process.Start("c:/windows/system32/shutdown.exe", "-s -t " + time);

posted @ 2021-07-28 18:50  北极星下落不明  阅读(384)  评论(0)    收藏  举报