我正在尝试创建一个程序来检查是否有一个进程可以阻止我的显示器进入睡眠状态。我一直通过运行powercfg /requests
手动执行此操作,并且希望使用.NET在计时器上运行此命令
问题是,命令提供的输出与在powershell中运行powercfg.exe
时不同。
运行进程的代码:
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程序。
发布于 2021-04-12 07:50:11
我最近也遇到了同样的问题。如果有人像我一样对这个问题的答案感兴趣,原因是构建的一点点性。当我用x86构建程序时,结果是不同的。但是,如果我在x64中构建,结果将与预期的一样。
https://stackoverflow.com/questions/64378725
复制相似问题