我正在尝试创建一个程序来检查是否有一个进程会阻止我的显示器进入睡眠状态。我一直在通过运行手动执行此操作,powercfg /requests
并且我想使用.NET 在计时器上运行此命令
问题是命令给我的输出与我powercfg.exe
在 powershell 中运行时不同。
运行该过程的代码:
var cmd = new Process { StartInfo = { FileName = "powercfg" } };
using (cmd)
{
cmd.StartInfo.Arguments = "/requests";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.Start();
string output = cmd.StandardOutput.ReadToEnd();
cmd.WaitForExit();
OutputTextBox.Text = output;
}
程序输出:
DISPLAY:
None.
SYSTEM:
[PROCESS] Legacy Kernel Caller
[PROCESS] Legacy Kernel Caller
[PROCESS] Legacy Kernel Caller
.
.
.
AWAYMODE:
None.
EXECUTION:
[PROCESS] Legacy Kernel Caller
[PROCESS] Legacy Kernel Caller
.
.
.
.
PERFBOOST:
None.
ACTIVELOCKSCREEN:
[PROCESS] Legacy Kernel Caller
.
.
.
PowerShell 输出
DISPLAY:
[PROCESS] \Device\HarddiskVolume4\Program Files (x86)\Google\Chrome\Application\chrome.exe
Video Wake Lock
SYSTEM:
[DRIVER] NVIDIA High Definition Audio (HDAUDIO\FUNC_01&VEN_10DE&DEV_0084&SUBSYS_1458371A&REV_1001\5&149e3f03&0&0001)
An audio stream is currently in use.
AWAYMODE:
None.
EXECUTION:
[PROCESS] \Device\HarddiskVolume4\Program Files (x86)\Google\Chrome\Application\chrome.exe
Playing audio
PERFBOOST:
None.
ACTIVELOCKSCREEN:
None.
我<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
以管理员身份和 VS 运行程序。