Tip: Windows internals using wmi

Colin Brown cbrown at metservice.com
Thu Oct 2 21:05:12 EDT 2003


Recently I was looking for remote management tools and came across
"Windows Management Instrumentation". There is a python interface
available:

 http://tgolden.sc.sabren.com/python/wmi.html

I was amazed how easy it became to access just about anything under
the hood (later versions of NT, 2000, XP) using a couple of lines of code!
If you have privileged access to remote computers you can interrogate
them as well. My attempts to modify things were less successful :-(

Colin Brown
PyNZ

With python, win32all and wmi installed, try these code snippets
to get some idea of what is available:

-------------------------------
import wmi
w = wmi.WMI()
for process in w.Win32_Process():
    if process == 'python':
        print process
-------------------------------
import wmi
c = wmi.WMI()
list = c.classes
out = []
for item in list:
 if item[:1] <> '_':
  out.append(item)

open('classes.txt','w').write('\r\n'.join(out))
print 'View classes.txt in a browser'
---------------------------
import wmi
c = wmi.WMI()
for x in c.Win32_NetworkAdapter():
    print x
--------------------------






More information about the Python-list mailing list