请教下如何刷新系统服务的状态
for service in c.Win32_Service(): if (service.Name).find('dmserver')>-1: print service.State while service.State=='Running': print service.State os.system('net stop dmserver') time.sleep(10)
#coding:utf-8import wmiimport timedef listservices(c): for service in c.Win32_Service(): print service.Caption,service.StartMode,service.Statedef watchservices(c): process_watcher=c.Win32_Process.watch_for("operation") while True: new_process=process_watcher() print new_process.Captiondef querystatus(c): wql="select name,state,status from Win32_Service where Name='MySQL51'" while True: print 'begin query service status:',time.ctime() for item in c.query(wql): print item if item.State.upper()=='STOPPED': return time.sleep(3) if __name__=='__main__': print 'begin' c = wmi.WMI() #listservices(c) querystatus(c) print 'end'
[解决办法]