在c#中怎么实现关机,冲起等操作
在c#中怎么实现关机,冲起等操作 --------------------编程问答-------------------- 参考代码:http://blog.csdn.net/jinjazz/archive/2008/04/17/2302095.aspx
把这行换成后面说明中的倒数第三条倒数第四条就是关机和重启
p.StartInfo.Arguments = "user32.dll,LockWorkStation";
--------------------编程问答-------------------- // ExitWindowsEx 函数可以退出登陆、关机或者重新启动系统
[DllImport( "user32.dll ",ExactSpelling=true,SetLastError=true)]
public static extern bool ExitWindowsEx(int 易做图, int rea);
private const int EWX_LOGOFF = 0x00000000; //注销
private const int EWX_SHUTDOWN = 0x00000001; //关机
private const int EWX_REBOOT = 0x00000002; //重起
ExitWindowsEx(EWX_SHUTDOWN ,0); --------------------编程问答-------------------- [DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
private static extern int ExitWindowsEx(int uFlags, int dwReserved);
//注销计算机
public void logout()
{
ExitWindowsEx(0, 0);
}
//关闭计算机
public void closepc()
{
//创建访问控制本地系统进程的对象实例
System.Diagnostics.Process myprocess = new System.Diagnostics.Process();
myprocess.StartInfo.FileName = "cmd.exe";
myprocess.StartInfo.UseShellExecute = false;
myprocess.StartInfo.RedirectStandardInput = true;
myprocess.StartInfo.RedirectStandardOutput = true;
myprocess.StartInfo.RedirectStandardError = true;
myprocess.StartInfo.CreateNoWindow = true;
myprocess.Start();
myprocess.StandardInput.WriteLine("shutdown -s -t 0");
}
//重新启动计算机
public void afreshstartpc()
{
//创建访问控制本地系统进程的对象实例
System.Diagnostics.Process myprocess = new System.Diagnostics.Process();
myprocess.StartInfo.FileName = "cmd.exe";
myprocess.StartInfo.UseShellExecute = false;
myprocess.StartInfo.RedirectStandardInput = true;
myprocess.StartInfo.RedirectStandardOutput = true;
myprocess.StartInfo.RedirectStandardError = true;
myprocess.StartInfo.CreateNoWindow = true;
myprocess.Start();
myprocess.StandardInput.WriteLine("shutdown -r -t 0");
} --------------------编程问答-------------------- mark --------------------编程问答-------------------- 调用系统进程,楼上正解 --------------------编程问答-------------------- api --------------------编程问答-------------------- 可以写一个关机服务 --------------------编程问答-------------------- 学习!
补充:.NET技术 , C#