Monthly Archives: July 2014

Creating Windows Services in Python

If you’ve ever been tasked with automating processes in MS Windows that run in the background or at night, you’ve likely worked with the Windows Task Scheduler (not to be confused with the Task Manager) and then some form of batch file, power shell scripts, or similar. If you were lucky enough to have Python installed on the server (assuming you are working on a server), you’ve probably run something like “python.exe” either directly or through a *.bat or *.cmd file. There are lots of tutorials online for this kind of thing.

But you might find that you want more control over the sequence of actions that make up your task, you might like some conditional controls, or have one action generate some output before another action starts. In short, you’ll enjoy being able to code all this in Python. Soon, you’ll start wonder if you can replace all your scheduling with a Python services that runs all the time and only performs certain actions, such as checking for the existence for a file, when a certain trigger (time of day) goes off. So how to write your Python service?

Two good posts explaining how to create a Windows service written in Python are this one ( and this one ( Either way, you will be using Mark Hammond’s Win32 extension, now available through Sourceforge. If you’re like me, you might’ve picked up a used copy of “Python – Programming on Win32” (Mark Hammond & Andy Robinson). Granted it’s quite dated (Jan 2000) but it’s a good reason for all things Python on Windows and has a whole chapter on “Windows NT services” that is the basis for what the links above illustrate.

There is a post on debugging Python win services here. If you use or are familiar with Active Python, then there are alternatives such as PythonCom, an example for which you can find here on stackoverflow. Finally, here is a recipe on how to do this using Windows Server 2003 Resource Kit Tools (RKT). If you’re like me and you’re jumping back and forth between different version of Windows Server, that may be useful.

Ok, this was a collection of useful links. Next post will have some code again.

Leave a comment

Filed under Python

Blogging Journey 2.0

Several years ago, I was working as a Professional Geologist, sitting by drill rigs, logging borehole cuttings, preparing paper logs, and arguing with the drillers about ROP and TCR… these days I don’t leave my desk, I’m logging automated data loads, manage digital well logs and wrestle with RDP access or TCP packets. Yet, I’m still in the geosciences. It’s been an interesting journey.

Initially, I used this blog to log my baby steps of becoming tech savvy. After making the official transition from a technological geologist to IT professional, there must have been to much to learn to find the time and blog about it. That’s when my editorial output waned. So, I’m making another attempt at reviving my page.  I have no particular audience in mind. Instead I like to think of it as merely a collection of useful tips and tricks for geo-technologists like myself who never went through any rigorous IT schooling but have learned to leverage technology to solve problems.

By now, I have 6 years of Python coding under my belt. I have moved from GIS to supporting a range of geoscience applications in the petroleum industry. I spent 3 years working with SQL Server and have spent the last year learning about Oracle. I once dabbled in Linux but will soon have to brush up on that. Also, after successfully completing a 4-course Python certificate, I’m now working towards completing one for C#/.NET.

Along the way, I’ve collected my share of notes and made my share of rookie mistakes. That’s not to say I don’t still feel like a rookie at least once every day. But I have gotten better about finding solutions quickly, asking the right questions, and knowing when it’s time to call in the Marines. So welcome to my blog, and leave me a message if you found something useful.

Leave a comment

Filed under Uncategorized