我该如何关闭电脑?

6 .net c# windows shutdown

如何使用C#关闭我的电脑?

dri*_*iis 10

一种简单的方法:使用Process.Start运行shutdown.exe.

  shutdown /s /t 0
Run Code Online (Sandbox Code Playgroud)

编程方式:P /调用ExitWindowsEx

这将是P/Invoke签名:

[DllImport("aygshell.dll", SetLastError="true")]
private static extern bool ExitWindowsEx(uint dwFlags, uint dwReserved);
Run Code Online (Sandbox Code Playgroud)

在任何情况下,运行代码的用户都需要关闭系统权限(通常不是问题,但要记住这一点).


lak*_*raj 5

不同方法:

A. System.Diagnostics.Process.Start("Shutdown"," - - -t 10");

B. Windows管理规范(WMI)

http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=36953

http://www.dreamincode.net/forums/showtopic33948.htm

C. System.Runtime.InteropServices Pinvoke

http://bytes.com/groups/net-c/251367-shutdown-my-computer-using-c

D.系统管理

http://www.geekpedia.com/code36_Shut-down-system-using-Csharp.html

在我提交之后,我看到很多其他人也发布了...