Auto Power on/off PC Using VBScript and ESP8266.

In this article, I have demonstrated vB script which will Trigger ESP8266 over HTTP. VBScript is checking the charging status and battery status. While bat file run VB script in every 10 seconds. In every 10 second my battery status and charging status measured by VB script. if the battery is below 20 and it’s not in charge it starts charging automatically. If battery status is above 95 and the charging status is charging then it will stop charging.


On Error Resume Next
Dim o
Dim bi
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery(“Select * from Win32_Battery”,,48)
For Each objItem in colItems
‘Wscript.Echo “EstimatedChargeRemaining: ” & objItem.EstimatedChargeRemaining
if objItem.EstimatedChargeRemaining < 20 and objItem.BatteryStatus=1 then Wscript.Echo “POWER ON” Set o = CreateObject(“MSXML2.XMLHTTP”) “GET”, “”, False o.send Wscript.Echo “done !!!” elseif objItem.EstimatedChargeRemaining > 95 and objItem.BatteryStatus=2 then
Wscript.Echo “POWER OFF”
Set o = CreateObject(“MSXML2.XMLHTTP”) “GET”, “”, False
Wscript.Echo “done !!!”
end if


@echo off
Pushd “%~dp0”
cscript //logo test_c.vbs
timeout /t 10 /nobreak
goto :loop

Share Post