如何创建一个应用程序来侦听Service Status Changed事件的服务。 (我不想重复检查所有服务)
修改
我需要它才能在Windows XP / 2000上运行
答案 0 :(得分:1)
在Vista及更高版本中,您可以使用NotifyServiceStatusChange
API。查看一些sample code on MSDN。
如果您要监控多项服务,则必须为要监控的每项服务拨打NotifyServiceStatusChange
。
答案 1 :(得分:0)
您正在寻找需要Vista的NotifyServiceStatusChange
。在2000 / XP上,您需要进行轮询。
答案 2 :(得分:-1)
您可以使用类似SELECT * FROM __InstanceModificationEvent WHERE TargetInstance ISA 'Win32_Service'
之类的WMI,然后检查Win32_Service类的State字段。