C#中,如何用代码分别实现系统注销,睡眠,休眠的功能?求高手解答!!

我请分析下,C#中,如何用代码分别实现系统注销,睡眠,休眠的功能?求高手解答!!
最新回答
梦散蝶逝

2025-06-27 19:28:21

//重启计算机代码
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = "shutdown.exe";
ps.Arguments = "-r -t 0";
Process.Start(ps);
//注销计算机代码
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = "shutdown.exe";
ps.Arguments = "-l";
Process.Start(ps);
//关闭计算机代码:
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = "shutdown.exe";
ps.Arguments = "-s -t 0";
Process.Start(ps);

备注:在用“ProcessStartInfo ”方法之前需要引入命名空间“using System.Diagnostics;” 睡眠和休眠的偶还不会呵呵呵~
狙击甜心

2025-06-27 14:43:41

百度一下windows 电源管理 api 你会有结论
CallNtPowerInformation

NTSTATUS WINAPI CallNtPowerInformation(
__in POWER_INFORMATION_LEVEL InformationLevel,
__in PVOID lpInputBuffer,
__in ULONG nInputBufferSize,
__out PVOID lpOutputBuffer,
__in ULONG nOutputBufferSize
);