搜尋

首頁  >  問答  >  主體

Python 怎麼操作windows系統服務

def listservices():
    import wmi
    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()

怎麼更改啟動類型以及狀態呢?

怪我咯怪我咯2717 天前785

全部回覆(1)我來回復

  • 滿天的星座

    滿天的星座2017-06-22 11:53:20

    模組作者的文檔裡有範例

    http://timgolden.me.uk/python...

    import wmi
    c = wmi.WMI()
    for service in c.Win32_Service(Name="seclogon"):
      result, = service.StopService()
      if result == 0:
        print "Service", service.Name, "stopped"
      else:
        print "Some problem"
      break
    else:
      print "Service not found"

    回覆
    0
  • 取消回覆