def get_service(name): """ Get the service descriptor for the given service name. @see: L{start_service}, L{stop_service}, L{pause_service}, L{resume_service} @type name: str @param name: Service unique name. You can get this value from the C{ServiceName} member of the service descriptors returned by L{get_services} or L{get_active_services}. @rtype: L{win32.ServiceStatusProcess} @return: Service status descriptor. """ with win32.OpenSCManager( dwDesiredAccess = win32.SC_MANAGER_ENUMERATE_SERVICE ) as hSCManager: with win32.OpenService(hSCManager, name, dwDesiredAccess = win32.SERVICE_QUERY_STATUS ) as hService: try: return win32.QueryServiceStatusEx(hService) except AttributeError: return win32.QueryServiceStatus(hService)
def stop_service(name): """ Stop the service given by name. @warn: This method requires UAC elevation in Windows Vista and above. @see: L{get_services}, L{get_active_services}, L{start_service}, L{pause_service}, L{resume_service} """ with win32.OpenSCManager( dwDesiredAccess=win32.SC_MANAGER_CONNECT) as hSCManager: with win32.OpenService( hSCManager, name, dwDesiredAccess=win32.SERVICE_STOP) as hService: win32.ControlService(hService, win32.SERVICE_CONTROL_STOP)
def start_service(name, argv=None): """ Start the service given by name. @warn: This method requires UAC elevation in Windows Vista and above. @see: L{stop_service}, L{pause_service}, L{resume_service} @type name: str @param name: Service unique name. You can get this value from the C{ServiceName} member of the service descriptors returned by L{get_services} or L{get_active_services}. """ with win32.OpenSCManager( dwDesiredAccess=win32.SC_MANAGER_CONNECT) as hSCManager: with win32.OpenService( hSCManager, name, dwDesiredAccess=win32.SERVICE_START) as hService: win32.StartService(hService)