We have a laptop that online for 24/7
in-case of power failure need to run a batch file or program
like below How to run a Windows application when the ethernet cable is connected?
We have a laptop that online for 24/7
in-case of power failure need to run a batch file or program
like below How to run a Windows application when the ethernet cable is connected?
This can be done via WMI
To do this, you create a WMI event customer with New-WmiEventConsumer
, of -ConsumerType CommandLine
so you can pass a -CommandLineTemplate
.
The event itself would be a WMI filter, created with New-WmiEventFilter
and -Query "select * from Win32_PowerManagementEvent where EventType = 4
" (4 = suspend).
Then tie customer and event with New-WmiFilterToConsumerBinding
.
Note that the problem with suspend on power failure is that you may not have much warning.
powercfg /batteryreport
or Get-WMIObject -Class Win32_Battery can't test myself.RegisterPowerSettingNotification
but that's assuming you have a program waiting in the background.