on error resume next strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\wmi") Set colItems = objWMIService.ExecQuery("Select * From BatteryStatus Where Voltage > 0") For Each objItem in colItems strCondition = objItem.PowerOnline Next if strCondition = "False" then msgbox " Please connect the power adapter to the laptop." WScript.Quit(0)