pedram@smash:~/blog$ cat python-wmi.md

# Python WMI · 2005-03-10

The Python WMI interface is very cool as it lets you write small yet functional snippets like the following print-job sniffer:

    import wmi

    w       = wmi.WMI()
    watcher = w.watch_for(
        notification_type = "Creation",
        wmi_class         = "Win32_PrintJob",
        delay_secs        = 1)

    while 1:
    job   = watcher()
    owner = str(job.Owner)

    print "user:    %s"  % (job.Owner)
    print "printer: %s"  % (job.Name)
    print "title:   %s"  % (job.Document)
    print "pages:   %d " % (job.TotalPages)
    print "-" * 80

The above snippet will watch the network for all print jobs and print the owner, document title, printer name and page count. More information about WMI (Windows Management Instrumentation) can be found on MSDN.

pedram@smash:~$
type help or ls /bin, or press ⌘Ctrl+K to jump anywhere