用C#编写自动关机的程序

来源:百度知道 编辑:UC知道 时间:2024/07/15 20:31:27
不要大量的复制!
要精简,且能看得懂!
谢谢!

//使用cmd的定时关机
private void button1_Click(object sender, EventArgs e)
{
if (DateTime.Now.Hour == int.Parse(comboBox1.Text) && DateTime.Now.Minute == numericUpDown2.Value)
{
msg=MessageBox.Show("您现在就要关机吗?建议先取消,设置具体时间关机!", "温馨提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if ( msg== DialogResult.Yes)
{
System.Diagnostics.Process.Start("cmd.exe", "shutdown -f -s -t 1"); //强制一秒倒计时关机!
}
else
return;
}

[DllImport("user32")]
public static extern long ExitWindowsEx(long uFlags,long dwReserved); //定义API变量
———————————————————————————————
long dwReserved ;
const int SHUTDOWN=1;//成员变量
———————————————————————————————
private void CloseComputer()
{
sh=ExitWindowEx(SHUTDOWN,dwReserved);
}
———————————————————————————————
你用一个timer控件,给一个时间,判断时间一到然后调用CloseComputer()函数进行关机

using System.Diagnostics;