/// <summary> /// 函数说明:修改操作系统 电源计划 /// mode说明: 1-平衡 2-节能 3-高性能 4-卓越性能 /// </summary> function SetPowerMode(mode: Integer): Boolean; const arrPolicys: array[1..4] of string = ('381b4222-f694-41f0-9685-ff5bb260df2e', //平衡 'a1841308-3541-4fab-bc81-f71556f20b4a', //节能 '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c', //高性能 'e9a42b02-d5df-448d-aa00-03f14749eb61' //卓越性能 - 部分操作系统版本不支持 ); var cmd: string; begin cmd := Format('-setactive %s', [arrPolicys[mode]]); ShellExecute(0, 'open', 'powercfg', PChar(cmd), nil, SW_HIDE); Result := True; end; procedure TForm1.Button1Click(Sender: TObject); begin SetPowerMode(1); //平衡 end; procedure TForm1.Button2Click(Sender: TObject); begin SetPowerMode(2); //节能 end; procedure TForm1.Button3Click(Sender: TObject); begin SetPowerMode(3); //高性能 end;
ShellExecute(0, 'open', 'powercfg', '/change /monitor-timeout-ac 99999', nil, SW_HIDE);