从命令行更改关闭盖子的作用?

bam*_*me2 11 power windows-7 command-line

我想知道是否有人知道可以一键更改 Windows 中的此设置的实用程序或命令。我经常需要在我的笔记本电脑上更换它,无论我想让它在盖子合上还是睡觉时什么都不做。

我确信可以从命令行以某种方式进行更改。

Gre*_*ine 22

取自Set On Lid Close Power 选项。这个页面上还有一两个脚本,但下面复制的方法是最好的,恕我直言。


您可以通过powercfg命令进行设置。

预配置的方案具有以下 GUID:

Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e  (Balanced)
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c  (High performance)
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a  (Power saver)
Run Code Online (Sandbox Code Playgroud)

我将在示例中使用 Balanced 方案,但您将使用以下提供的 GUID:

powercfg -GETACTIVESCHEME
Run Code Online (Sandbox Code Playgroud)

通过使用您的方案 GUID 运行查询命令,您可以找到子组和电源设置的 GUID 以及每个电源设置的索引值:

powercfg -Q 381b4222-f694-41f0-9685-ff5bb260df2e
Run Code Online (Sandbox Code Playgroud)

查看输出,您会发现您想要的子组 GUID 是:

Subgroup GUID: 4f971e89-eebd-4455-a8de-9e59040e7347  (Power buttons and lid)
Run Code Online (Sandbox Code Playgroud)

和电源设置:

Power Setting GUID: 5ca83367-6e45-459f-a27b-476b1d01c936  (Lid close action)
Run Code Online (Sandbox Code Playgroud)

带索引选项:

Possible Setting Index: 000
Possible Setting Friendly Name: Do nothing
Possible Setting Index: 001
Possible Setting Friendly Name: Sleep
Possible Setting Index: 002
Possible Setting Friendly Name: Hibernate
Possible Setting Index: 003
Possible Setting Friendly Name: Shut down
Run Code Online (Sandbox Code Playgroud)

因此,为了将您的系统配置为在盖子关闭时关闭,您可以运行:

powercfg -SETACVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 3
powercfg -SETDCVALUEINDEX 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 3
Run Code Online (Sandbox Code Playgroud)

注意:这两行是相同的,除了:

  • ACSETACVALUEINDEX为“插中”行动,和;
  • DCSETDCVALUEINDEX对“关于电池”的行动。

附加说明

这篇文章

通过命令行进行的设置必须遵循

powercfg -setactive <GUID>`
Run Code Online (Sandbox Code Playgroud)

也就是说,对于“平衡”

powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e
Run Code Online (Sandbox Code Playgroud)

请注意,我没有阻止引用,因为它弄乱了相当长的代码行。所以为了格式化,我没有加引号。


Mar*_*orf 5

以下似乎是从命令行更改当前活动电源方案的行为的最简单且有些可读的方法(感谢w17t 的回答TenForums 帖子):

DoNothingWhenClosingTheLid.bat
::Do nothing when you close the lid
powercfg /setacvalueindex scheme_current sub_buttons lidaction 0
powercfg /setdcvalueindex scheme_current sub_buttons lidaction 0

::Re-activate current scheme to make settings take effect immediately
powercfg /setactive scheme_current
Run Code Online (Sandbox Code Playgroud) GoToSleepWhenClosingTheLid.bat
::Go to sleep/standby mode when you close the lid
powercfg /setacvalueindex scheme_current sub_buttons lidaction 1
powercfg /setdcvalueindex scheme_current sub_buttons lidaction 1

::Re-activate current scheme to make settings take effect immediately
powercfg /setactive scheme_current
Run Code Online (Sandbox Code Playgroud)


Kyl*_*Mit 5

这是使用 WMIPower Policy Provider类和Cim Cmdlets模块的另一种策略

$powerNamespace = @{ Namespace = 'root\cimv2\power' }

# https://docs.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-lid-switch-close-action
enum LidAction {
    DoNothing = 0
    Sleep = 1
    Hibernate = 2
    ShutDown = 3
}

enum PowerSupply {
    AC # Plugged In
    DC # On Battery
}

# get active plan
$curPlan = Get-CimInstance @powerNamespace -Class Win32_PowerPlan -Filter "IsActive = TRUE"

# get lid closed setting
$lidSetting = Get-CimInstance @powerNamespace -ClassName Win32_Powersetting -Filter "ElementName = 'Lid close action'"

# get guids
$planGuid = [Regex]::Matches($curPlan.InstanceId, "{.*}" ).Value
$lidGuid = [Regex]::Matches($lidSetting.InstanceID, "{.*}" ).Value

# get plugged in lid setting    
$pluggedInLidSetting = Get-CimInstance @powerNamespace -ClassName Win32_PowerSettingDataIndex `
    -Filter "InstanceID = 'Microsoft:PowerSettingDataIndex\\$planGuid\\$([PowerSupply]::AC)\\$lidGuid'"

# set lid action to do nothing
$pluggedInLidSetting | Set-CimInstance -Property @{ SettingIndexValue = [int][LidAction]::DoNothing }

# refresh to activate
$curPlan | Invoke-CimMethod -MethodName Activate
Run Code Online (Sandbox Code Playgroud)

进一步阅读