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);

浙公网安备 33010602011771号