Search This Blog

Monday, December 30, 2019

Using WMI in Python

Using WMI in Python

Two steps 
  1. Install pywin32 to support wmi commands 
  2. import wmi in python code

INSTALL PYWIIN32
  1. Open Python Terminal 
  2. Type pip install pywin32 and press enter. This will install pywin32
IMPORT WMI PYTHON

Like anyother import command you just need to use import wmi. Below is the sample code which get the list of services that is in stopped state (not running )

import wmi

c = wmi.WMI ()
for s in c.Win32_Service ():
  if s.State == 'Stopped':
    print(s.Caption, s.State)

No comments:

Post a Comment