[Tutor] Automating Windows (Maintenance)
Tiger12506
keridee at jayco.net
Tue Jul 3 00:36:47 CEST 2007
> "Daniel McQuay" <simplebob at gmail.com> 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.
Watch and be amazed...
####################
import os
os.system('defrag.exe c:')
os.system('pause') # waits for keypress, delete if you don't
want it
os.system('chkdsk.exe c:')
####################
For more control over defrag and chkdsk, open a command prompt and type in
program name followed by a space and then /? ex. defrag.exe /?
The cleanup temp files is more difficult. It depends on how much you want to
do. Usually it is sufficient to delete the contents of the windows/temp
folder. This will delete cookies, temporary files, internet temp files that
are commonly cleaned up by sys admin. So you can add os.system('del /s /f
/s /q C:\windows\temp\*') Again, the meaning of the command switches can be
found by typing in prompt 'del /?' (without quotes)
That takes care of most of your problems, no? There are more things that you
wish to automate, I'm sure. Easiest is to search for the command line
equivalents of all your normal tasks.
For checking processes, you can search for a tool on the internet that lists
currently running processes. Here's an example.
http://technet2.microsoft.com/windowsserver/en/library/d41f22ce-93c8-4884-90db-f4b8e8fdc3ec1033.mspx?mfr=true
You would have to read those from a file, though. Not a problem with python,
right?
If you are really interested in a program that does this, I could be
encouraged to write one for you (in C) - Although, it would most certainly
be better to find api s that allow you to do this in python. Google.
HTH,
Jacob S.
More information about the Tutor
mailing list