V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Jun 22, 2017 · 3762 views
    This topic created in 3241 days ago, the information mentioned may be changed or developed.

    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 replies    2021-01-08 17:41:39 +08:00
    sunhk25
        1
    sunhk25  
       Jun 22, 2017
    linus3389
        2
    linus3389  
       Jun 22, 2017
    os.system("net stop/start service_name")

    状态可以 sc query service_name
    LEQ4ctL0lmh7q795
        4
    LEQ4ctL0lmh7q795  
       Jan 8, 2021
    @NoAnyLove
    👍
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4248 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 00:55 · PVG 08:55 · LAX 17:55 · JFK 20:55
    ♥ Do have faith in what you're doing.