如何使用powershell/vbs/wmi/...让笔记本电脑进入睡眠状态?

Chr*_*son 2 powershell electrical-power wmi

我希望能够从命令行让我的笔记本电脑进入睡眠状态。根据微软的说法,Win32_Battery WMI 类有一个 SetPowerState 方法,看起来它应该能够做到这一点,但是,在我尝试过的几台笔记本电脑上,我只是收到不同的错误,表明此方法未实现或其他各种故障:

-> gwmi Win32_Class
Get-WmiObject : Retrieving the COM class factory for component with CLSID {EB87E1BD-3233-11D2-AEC9-00C04FB68820} failed
 due to the following error: 80040154.
At line:1 char:5
+ gwmi <<<<  Win32_Class
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Run Code Online (Sandbox Code Playgroud)

有没有笔记本电脑实现这个?知道另一种方法吗?不必是 WMI,任何使机器处于与关闭盖子在大多数笔记本电脑上相同的低功耗状态的东西。

小智 5

您可以在 PowerShell 提示符中使用以下命令:

Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState("Suspend", $false, $true)
Run Code Online (Sandbox Code Playgroud)