日期:2014-05-18 浏览次数:21244 次
//------------关机方法
public void guanji()
{
try
{
//启动本地程序并执行命令
Process.Start("Shutdown.exe", " -s -t 0");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//----------重启重启
public void chongqi()
{
try
{
//启动本地程序并执行命令
Process.Start("shutdown.exe"," -r -t 0");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//赠送一个使用win32API函数注销的
//===================================================================================注销 函数 声明
[DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
//ExitWindowsEx 函数
private static extern int ExitWindowsEx(int uFlags, int dwReserved);
//======================================================================================
public void zhuxiao() //注销
{
ExitWindowsEx(0, 0);
}
------解决方案--------------------
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c shutdown.exe -r -t 0";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("exit");
------解决方案--------------------
操作系统提供了关机控制的api函数
------解决方案--------------------
up
------解决方案--------------------
用API好些,用DOS命令如果系统没那命令就不可以了,
------解决方案--------------------
private void button1_Click(object sender, EventArgs e)//关机
{
Process process = new Process();
process.StartInfo.FileName = "shutdown.exe";
process.StartInfo.Arguments = "-s -t 0";
process.Start();
}
private void button2_Click(object sender, EventArgs e)//重启
{
Process process = new Process();
process.StartInfo.FileName = "shutdown.exe";
process.StartInfo.Arguments = "-r -t 0";
process.Start();
}
------解决方案--------------------
向7楼学习
------解决方案--------------------
七楼的方法还是相当简单的,
学习学习
------解决方案--------------------
顶一个