Sunday, July 6, 2008

Get the windows service state using Python

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

2 comments:

Bookmarks about Windows said...

[...] - 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/ - [...]

mike said...

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