c# - 为什么我的程序中 "powercfg"命令的输出与在 powershell 中运行时不同

标签 c# .net powercfg

我正在尝试创建一个程序来检查是否有一个进程会阻止我的显示器进入休眠状态。我一直通过运行 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 作为管理员。

最佳答案

我最近遇到了同样的问题。以防万一有人像我一样有兴趣知道这个问题的答案,原因是构建的位。当我在 x86 中构建程序时,结果是不同的。但是如果我在 x64 中构建,结果正如预期的那样。

关于c# - 为什么我的程序中 "powercfg"命令的输出与在 powershell 中运行时不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64378725/

相关文章:

c# - Emgu OpenCV Intptr 到 IplImage?

c# - ASP .NET - 使用 asp :CheckBox in ListView

.net - 使用 Wix 安装程序 3.11 检测 .Net 4.7

c# - IntPtr.ToInt32() Marshal.ThrowExceptionForHR() - 查询 GAC

c# - SignInManager,它是什么以及如何使用,何时使用?

c# - 跨请求保留新声明

windows - 如何找出hiberfil.sys大小?

python - 通过python确认当前的电源计划

c# - 如果 DataReader 返回两个结果集,则使用 DataTable.Load() 方法不起作用