Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
    def get_service_from_display_name(displayName):
        """
        Get the service unique name given its display name.

        @see: L{get_service}

        @type  displayName: str
        @param displayName: Service display name. You can get this value from
            the C{DisplayName} member of the service descriptors returned by
            L{get_services} or L{get_active_services}.

        @rtype:  str
        @return: Service unique name.
        """
        with win32.OpenSCManager(dwDesiredAccess=win32.
                                 SC_MANAGER_ENUMERATE_SERVICE) as hSCManager:
            return win32.GetServiceKeyName(hSCManager, displayName)
Beispiel #4
0
    def get_active_services():
        """
        Retrieve a list of all active system services.

        @see: L{get_services},
            L{start_service}, L{stop_service},
            L{pause_service}, L{resume_service}

        @rtype:  list( L{win32.ServiceStatusProcessEntry} )
        @return: List of service status descriptors.
        """
        with win32.OpenSCManager(dwDesiredAccess=win32.
                                 SC_MANAGER_ENUMERATE_SERVICE) as hSCManager:
            return [ entry for entry in win32.EnumServicesStatusEx(hSCManager,
                        dwServiceType  = win32.SERVICE_WIN32,
                        dwServiceState = win32.SERVICE_ACTIVE) \
                    if entry.ProcessId ]
Beispiel #5
0
    def get_services():
        """
        Retrieve a list of all system services.

        @see: L{get_active_services},
            L{start_service}, L{stop_service},
            L{pause_service}, L{resume_service}

        @rtype:  list( L{win32.ServiceStatusProcessEntry} )
        @return: List of service status descriptors.
        """
        with win32.OpenSCManager(dwDesiredAccess=win32.
                                 SC_MANAGER_ENUMERATE_SERVICE) as hSCManager:
            try:
                return win32.EnumServicesStatusEx(hSCManager)
            except AttributeError:
                return win32.EnumServicesStatus(hSCManager)
Beispiel #6
0
    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)