Batch file 如果电脑电池电量下降18%,如何使电脑休眠?

Batch file 如果电脑电池电量下降18%,如何使电脑休眠?,batch-file,cmd,window,Batch File,Cmd,Window,我通过- WMIC PATH Win32_Battery Get EstimatedChargeRemaining 输出为=> 估计费用维持 一百 另外,我可以使用如下命令休眠我的电脑: shutdown /h 那么,我为什么要编写这样一个脚本,当电池电量下降到20%以下时,它就会休眠我的电脑, 我该怎么做?此外,当我再次打开电源时,它不会再次休眠,我的意思是只运行一次,当电池电量超过21%时,再次激活该功能,因此这是一项可行的服务。任何帮助都是值得的。。。提前谢谢 我知道windows中的

我通过-

WMIC PATH Win32_Battery Get EstimatedChargeRemaining
输出为=> 估计费用维持 一百

另外,我可以使用如下命令休眠我的电脑:

shutdown /h
那么,我为什么要编写这样一个脚本,当电池电量下降到20%以下时,它就会休眠我的电脑,
我该怎么做?此外,当我再次打开电源时,它不会再次休眠,我的意思是只运行一次,当电池电量超过21%时,再次激活该功能,因此这是一项可行的服务。任何帮助都是值得的。。。提前谢谢

我知道windows中的这些功能,但我想创建一种即使其他人试图启动笔记本电脑也能自动休眠的功能,这样打开的进程或其他正在运行的任务就不会突然耗尽/或崩溃。最后,我在node中编写了这个程序,并用

node Autohibernate.js
因此,节点程序将由该程序执行。最后,为了使它在隐藏模式下运行,即使电脑重新启动,我制作了一个vbscript程序来实现这一点。是这样的-

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\autohibernate.bat" & Chr(34), 0
Set WshShell = Nothing
最后是节点程序,如下图所示的autohibernate.js-

const { exec, spawn } = require("child_process");
let current;
let critical = 18; // Battery level at which hibernates.
let repeatAfterActionFired = 1; //In minutes.
let generalCheckTimer = 3; // Check after every this time(in second).

async function somelife() {
  exec("WMIC PATH Win32_Battery Get EstimatedChargeRemaining", (err, stdout, stderr) => {
    current = stdout.slice(29);
    console.log("battery-", current);
    if (current > critical) {
      checkAndHibernate();
    } else {
      console.log(
        `Hibernation Fired, Next checkAndHibernate after ${repeatAfterActionFired} minutes.`
      );
      setTimeout(() => {
        checkAndHibernate();
      }, repeatAfterActionFired * 60 * 1_000);

      exec("shutdown /h");
      // exec()
    }
  });
}
const checkAndHibernate = () =>
  setTimeout(() => {
    somelife();
  }, generalCheckTimer * 1_000);
checkAndHibernate();
谢谢,斯塔克