[Tutor] Automating Windows (Maintenance)

Tim Golden mail at timgolden.me.uk
Mon Jul 2 20:45:14 CEST 2007

Daniel McQuay wrote:
> I wondering if any one uses Python to do such things as defragment, 
> clean up temp files, check for hard drive errors, check for unusual 
> processes running, and so on. I am in charge of maintaining a lot of 
> Windows PC's and it would make life so much easier if i could automate 
> some of these tasks. I am pretty new to Python but I seem to understand 
> it a little better than VB Script. I have been Googling Windows 
> Automation and getting some pretty good links but most if not all are 
> done using batch scripts and VB Script. I have a batch script that 
> cleans up temp files and defragments the hard drive but I would like to 
> know if  Python is a good candidate for this or should I just stick to 
> what is built into Windows.

WMI is probably the answer to a lot of those kind of things. In
general, if you have a sys-adminy task to do under Windows,
put "WMI <sys-adminy-task>" into your favourite search engine
and see what comes out.[0]

Then get the Python WMI module [1] and convert the example
from VBS to Python.

And Bob's your uncle. [2]


[0] eg, http://msdn2.microsoft.com/EN-US/library/aa394592.aspx
[1] http://timgolden.me.uk/python/wmi.html
[2] Well *my* uncle, at least: I do actually have an uncle called Bob.

More information about the Tutor mailing list