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.

test_c.vbs

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”) o.open “GET”, “http://192.168.1.8/LED=1”, False o.send Wscript.Echo “done !!!” elseif objItem.EstimatedChargeRemaining > 95 and objItem.BatteryStatus=2 then
Wscript.Echo “POWER OFF”
Set o = CreateObject(“MSXML2.XMLHTTP”)
o.open “GET”, “http://192.168.1.8/LED=1”, False
o.send
Wscript.Echo “done !!!”
end if
Next

Trigger.bat

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

Share Post