如何通过c#代码运行powercfg的函数?
例如,我想运行下面的命令,对于Set,关闭显示:从不
powercfg -CHANGE -monitor -timeout -ac 0 发布于 2010-11-24 23:35:11
用Process.Start调用它
Process.Start("powercfg", "-CHANGE -monitor -timeout -ac 0");发布于 2010-11-24 23:35:38
您可以调用Process.Start来运行可执行文件。
例如:
Process.Start(fileName: "powercfg", arguments: "-CHANGE -monitor -timeout -ac 0");但是,如果您只想在程序运行时禁用自动关闭功能,则应改为处理WM_SYSCOMMAND消息。
例如:
protected override void WndProc(ref Message m) {
const int SC_SCREENSAVE = 0xF140, SC_MONITORPOWER = 0xF170;
const int WM_SYSCOMMAND = 0x0112;
if (m.Msg == WM_SYSCOMMAND) {
if ((m.WParam.ToInt64() & 0xFFF0) == SC_SCREENSAVE || (m.WParam.ToInt64() & 0xFFF0) == SC_MONITORPOWER) {
m.Result = 0;
return;
}
}
base.WndProc(ref m);
}发布于 2010-11-24 23:35:23
您可以使用Process类从C#运行powercfg。
https://stackoverflow.com/questions/4268522
复制相似问题