+ -
当前位置:首页 → 问答吧 → 请教下如何刷新系统服务的状态

请教下如何刷新系统服务的状态

时间:2011-10-21

来源:互联网

Python code

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)




请教下 我现在使用这种方法能达到自动查找到我要的服务 并且关闭服务
但是那个while判断里 这么写虽然服务已经被关掉了 但while的 service.State状态没有变化 这么写就是永远循环了 请教下 代码刷新下服务状态怎么写?

作者: mouseweiwei   发布时间: 2011-10-21

这个对象是在前面的代码创建的吧,所以状态还是前面获取到的。但也不能使用在循环中不断创建销毁对象这种暴力办法。wmi我也不太熟,我看看有没有刷新或者监控的方法。

作者: panzifei   发布时间: 2011-10-21

其实我也就看网站上的文章,你也可以看看:
http://timgolden.me.uk/python/wmi/tutorial.html
http://timgolden.me.uk/python/wmi/cookbook.html
wmi是啥你可以搜一下看,这东西内容也比较多,管理windows系统用的,也挺复杂。

作者: panzifei   发布时间: 2011-10-21