V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Kakarrot
V2EX  ›  Python

Python 如何控制 windows 系统服务?

  •  
  •   Kakarrot · 2017-06-22 09:11:50 +08:00 · 3178 次点击
    这是一个创建于 2490 天前的主题,其中的信息可能已经有所发展或是发生改变。

    import wmi

    def listservices():

    c = wmi.WMI()
    for service in c.Win32_Service():
        #print(service.Caption,service.StartMode,service.State)
        print(service.Caption)     #名称
        print(service.StartMode)   #启动类型
        print(service.State)       #状态
    

    if name=='main': listservices()

    可以获取当前全部的系统服务的名称 启动类型、状态 但是要怎么才可以更改呢?

    4 条回复    2021-01-08 17:41:39 +08:00
    sunhk25
        1
    sunhk25  
       2017-06-22 09:58:58 +08:00
    linus3389
        2
    linus3389  
       2017-06-22 09:59:28 +08:00
    os.system("net stop/start service_name")

    状态可以 sc query service_name
    NoAnyLove
        3
    NoAnyLove  
       2017-06-22 10:21:52 +08:00
    justaman
        4
    justaman  
       2021-01-08 17:41:39 +08:00
    @NoAnyLove
    👍
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5581 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 06:40 · PVG 14:40 · LAX 23:40 · JFK 02:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.