title: Windows-10 battery indicator Visual Basic Script
body: <p>I got some code from the internet for a warning indicator. I use it for warning me when battery is charging and the battery level is above 80%.</p>
  
  <p>But I also want to use it to warn me when the battery level is below 20%. I have added a line for this 20% warning, but it is not working. It works when battery is above 80%, but not when battery is below 20%.</p>
  
  <p>I think the code is in Visual Basic Script (VBS).</p>
  
  <p>Please help.</p>
  
  <p>I have already searched on other forums and this one, but could not find such a program anywhere.</p>
  
  <pre><code>set oLocator = CreateObject("WbemScripting.SWbemLocator")
  set oServices = oLocator.ConnectServer(".","root\wmi")
  set oResults = oServices.ExecQuery("select * from batteryfullchargedcapacity")
  for each oResult in oResults
     iFull = oResult.FullChargedCapacity
  next
  
  while (1)
    set oResults = oServices.ExecQuery("select * from batterystatus")
    for each oResult in oResults
      iRemaining = oResult.RemainingCapacity
      bCharging = oResult.Charging
    next
    iPercent = ((iRemaining / iFull) * 100) mod 100
    if bCharging and (iPercent &gt; 80) Then msgbox "Battery is charged now more than 80%. Please stop charging for optimal battery life."
    if bCharging and (iPercent &lt; 20) Then msgbox "Battery is discharging and is below 20%. Please switch on charging immediately."
    wscript.sleep 30000 ' 5 minutes
  wend
  </code></pre>