~ Mayank Johri’s Tips ~

July 5, 2008

Get the windows service state using Python

Filed under: Python, Tips, Windows — mayankjohri @ 10:55 pm
Tags: ,

following code can be used to find if any service is installed and if so then return the state of the service.

import wmi

class servicePython():
    def __init__(self, serviceName):
        self.c = wmi.WMI ()
        self.serviceName = serviceName

    def setServiceName(self, serviceName):
        self.serviceName = serviceName

    def getStatus(self):   
        srv = c.Win32_Service (name=self.serviceName)
        if srv != []:
            return c.Status
        return False

3 Comments »

  1. [...] – bookmarked by 2 members originally found by Waninkoko on July 13, 2008 Get the windows service state using Python http://mayankjohri.wordpress.com/2008/07/05/get-the-windows-service-state-using-python/ – [...]

    Pingback by Bookmarks about Windows — July 17, 2008 @ 1:00 am | Reply

  2. Thanks !

    Comment by Poizebottutemi — August 3, 2008 @ 3:55 am | Reply

  3. Thank you for this piece of code. I was looking for this.

    Comment by mike — December 15, 2008 @ 12:53 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.