Hey guys,
So I'm trying to create an event registration from a WMI notifier query. What I would like to happen is for the wmi notifier to recognize a change in a specific service's state - then in action to this change - run a function I devised to simply turn the service back on. Now I know that the function works correctly and I know from wbemtest that toggling the service does create an event with my given query (I'm using the adobe updater service to test with on my machine). While I have this running in the console and the event registered- nothing ever happens when I disable the service - looks as if my function is never ran.
One thing I did notice was that my event notifier query returns this output "InstanceModificationEvent=<no key>" Whenever I toggle the service.
Am I missing a step here? Do I need to do something more with the event notifier query??
I will paste my code below.
Function StartServ {if ($global:WMIServiceObject.State -eq "Stopped"){
$global:WMIServiceObject.StartService() }
else {
break
}
}
$Global:WMIServiceObject = Get-WmiObject -Class Win32_Service | where {$_.Name -eq "AdobeARMService"}
$EventQuery = "Select * from __InstanceModificationEvent within 1 Where TargetInstance ISA 'Win32_Service' and TargetInstance.Name = 'AdobeARMservice'"
$Action = { StartServ }
Register-WmiEvent -Query $EventQuery -Action $Action
My shell session (inside powergui) is running as admin so I don't believe that is the issue. Is there a way in my shell session to see if a notification is being recorded at all?
Thanks