当前位置: 首页>>代码示例>>Python>>正文


Python win32service.OpenSCManager方法代码示例

本文整理汇总了Python中win32service.OpenSCManager方法的典型用法代码示例。如果您正苦于以下问题:Python win32service.OpenSCManager方法的具体用法?Python win32service.OpenSCManager怎么用?Python win32service.OpenSCManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32service的用法示例。


在下文中一共展示了win32service.OpenSCManager方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EnumServices

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def EnumServices():
    resume = 0
    accessSCM = win32con.GENERIC_READ
    accessSrv = win32service.SC_MANAGER_ALL_ACCESS

    #Open Service Control Manager
    hscm = win32service.OpenSCManager(None, None, accessSCM)

    #Enumerate Service Control Manager DB

    typeFilter = win32service.SERVICE_WIN32
    stateFilter = win32service.SERVICE_STATE_ALL

    statuses = win32service.EnumServicesStatus(hscm, typeFilter, stateFilter)
    for (short_name, desc, status) in statuses:
        print short_name, desc, status 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:win32servicedemo.py

示例2: RemoveService

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def RemoveService(serviceName):
    try:
        import perfmon
        perfmon.UnloadPerfCounterTextStrings("python.exe "+serviceName)
    except (ImportError, win32api.error):
        pass

    hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
    try:
        hs = SmartOpenService(hscm, serviceName, win32service.SERVICE_ALL_ACCESS)
        win32service.DeleteService(hs)
        win32service.CloseServiceHandle(hs)
    finally:
        win32service.CloseServiceHandle(hscm)

    import win32evtlogutil
    try:
        win32evtlogutil.RemoveSourceFromRegistry(serviceName)
    except win32api.error:
        pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:win32serviceutil.py

示例3: create_driver_service

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def create_driver_service(logger):
    """Creates the service for winpmem"""
    # Must have absolute path here.
    if hasattr(sys, "frozen"):
        driver = os.path.join(sys._MEIPASS, get_winpmem_name())
    else:
        driver = os.path.join(os.getcwd(), get_winpmem_name())

    h_scm = win32service.OpenSCManager(
            None, None, win32service.SC_MANAGER_CREATE_SERVICE)

    try:
        h_svc = win32service.CreateService(
                h_scm, "pmem", "pmem",
                win32service.SERVICE_ALL_ACCESS,
                win32service.SERVICE_KERNEL_DRIVER,
                win32service.SERVICE_DEMAND_START,
                win32service.SERVICE_ERROR_IGNORE,
                driver,
                None, 0, None, None, None)
    except win32service.error, e:
        logger.error(e)
        h_svc = win32service.OpenService(h_scm, "pmem",
                                         win32service.SERVICE_ALL_ACCESS) 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:26,代码来源:utils.py

示例4: __init__

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def __init__(self,plugin):
        """
        This initializes the class, and saves the plugin reference for use in the new thread.
        """
        self.plugin = plugin
        self.file = None
        self.connecting = False
        self.receiving = False
        self.sentMessageOnce = True
        self.receivingTimeout = None

        try:
            scmanager = win32service.OpenSCManager(None, None, win32service.SC_MANAGER_CONNECT)
            self.service = win32service.OpenService(scmanager, MCE_SERVICE_NAME, win32service.SERVICE_START | win32service.SERVICE_QUERY_STATUS)
            win32service.CloseServiceHandle(scmanager)
        except:
            self.service = None 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:19,代码来源:__init__.py

示例5: InstallService

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def InstallService(pythonClassString, serviceName, displayName, startType = None, errorControl = None, bRunInteractive = 0, serviceDeps = None, userName = None, password = None, exeName = None, perfMonIni = None, perfMonDll = None, exeArgs = None, description = None):
    # Handle the default arguments.
    if startType is None:
        startType = win32service.SERVICE_DEMAND_START
    serviceType = win32service.SERVICE_WIN32_OWN_PROCESS
    if bRunInteractive:
        serviceType = serviceType | win32service.SERVICE_INTERACTIVE_PROCESS
    if errorControl is None:
        errorControl = win32service.SERVICE_ERROR_NORMAL

    exeName = '"%s"' % LocatePythonServiceExe(exeName) # None here means use default PythonService.exe
    commandLine = _GetCommandLine(exeName, exeArgs)
    hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
    try:
        hs = win32service.CreateService(hscm,
                                serviceName,
                                displayName,
                                win32service.SERVICE_ALL_ACCESS,         # desired access
                    serviceType,        # service type
                    startType,
                    errorControl,       # error control type
                    commandLine,
                    None,
                    0,
                    serviceDeps,
                    userName,
                    password)
        if description is not None:
            try:
                win32service.ChangeServiceConfig2(hs,win32service.SERVICE_CONFIG_DESCRIPTION,description)
            except NotImplementedError:
                pass    ## ChangeServiceConfig2 and description do not exist on NT
        win32service.CloseServiceHandle(hs)
    finally:
        win32service.CloseServiceHandle(hscm)
    InstallPythonClassString(pythonClassString, serviceName)
    # If I have performance monitor info to install, do that.
    if perfMonIni is not None:
        InstallPerfmonForService(serviceName, perfMonIni, perfMonDll) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:41,代码来源:win32serviceutil.py

示例6: ControlService

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def ControlService(serviceName, code, machine = None):
    hscm = win32service.OpenSCManager(machine,None,win32service.SC_MANAGER_ALL_ACCESS)
    try:

        hs = SmartOpenService(hscm, serviceName, win32service.SERVICE_ALL_ACCESS)
        try:
            status = win32service.ControlService(hs, code)
        finally:
            win32service.CloseServiceHandle(hs)
    finally:
        win32service.CloseServiceHandle(hscm)
    return status 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:win32serviceutil.py

示例7: StartService

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def StartService(serviceName, args = None, machine = None):
    hscm = win32service.OpenSCManager(machine,None,win32service.SC_MANAGER_ALL_ACCESS)
    try:

        hs = SmartOpenService(hscm, serviceName, win32service.SERVICE_ALL_ACCESS)
        try:
            win32service.StartService(hs, args)
        finally:
            win32service.CloseServiceHandle(hs)
    finally:
        win32service.CloseServiceHandle(hscm) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:win32serviceutil.py

示例8: QueryServiceStatus

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def QueryServiceStatus(serviceName, machine=None):
    hscm = win32service.OpenSCManager(machine,None,win32service.SC_MANAGER_CONNECT)
    try:

        hs = SmartOpenService(hscm, serviceName, win32service.SERVICE_QUERY_STATUS)
        try:
            status = win32service.QueryServiceStatus(hs)
        finally:
            win32service.CloseServiceHandle(hs)
    finally:
        win32service.CloseServiceHandle(hscm)
    return status 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:win32serviceutil.py

示例9: __init__

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def __init__(self, machineName = ''):
		dialog.Dialog.__init__(self, self.GetResource())
		self.HookCommand(self.OnListEvent, self.IDC_LIST)
		self.HookCommand(self.OnStartCmd, self.IDC_START)
		self.HookCommand(self.OnStopCmd, self.IDC_STOP)
		self.HookCommand(self.OnPauseCmd, self.IDC_PAUSE)
		self.HookCommand(self.OnContinueCmd, self.IDC_CONTINUE)
		self.HookCommand(self.OnStartupCmd, self.IDC_STARTUP)
		self.machineName = machineName
		self.scm = win32service.OpenSCManager(self.machineName, None, win32service.SC_MANAGER_ALL_ACCESS) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:ControlService.py

示例10: _get_service_control_manager

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def _get_service_control_manager(
            scm_access=win32service.SC_MANAGER_CONNECT):
        hscm = win32service.OpenSCManager(None, None, scm_access)
        try:
            yield hscm
        finally:
            win32service.CloseServiceHandle(hscm) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:9,代码来源:windows.py

示例11: ChangeServiceConfig

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def ChangeServiceConfig(pythonClassString, serviceName, startType = None, errorControl = None, bRunInteractive = 0, serviceDeps = None, userName = None, password = None, exeName = None, displayName = None, perfMonIni = None, perfMonDll = None, exeArgs = None, description = None):
    # Before doing anything, remove any perfmon counters.
    try:
        import perfmon
        perfmon.UnloadPerfCounterTextStrings("python.exe "+serviceName)
    except (ImportError, win32api.error):
        pass

    # The EXE location may have changed
    exeName = '"%s"' % LocatePythonServiceExe(exeName)

    # Handle the default arguments.
    if startType is None: startType = win32service.SERVICE_NO_CHANGE
    if errorControl is None: errorControl = win32service.SERVICE_NO_CHANGE

    hscm = win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
    serviceType = win32service.SERVICE_WIN32_OWN_PROCESS
    if bRunInteractive:
        serviceType = serviceType | win32service.SERVICE_INTERACTIVE_PROCESS
    commandLine = _GetCommandLine(exeName, exeArgs)
    try:
        hs = SmartOpenService(hscm, serviceName, win32service.SERVICE_ALL_ACCESS)
        try:

            win32service.ChangeServiceConfig(hs,
                serviceType,  # service type
                startType,
                errorControl,       # error control type
                commandLine,
                None,
                0,
                serviceDeps,
                userName,
                password,
                displayName)
            if description is not None:
                try:
                    win32service.ChangeServiceConfig2(hs,win32service.SERVICE_CONFIG_DESCRIPTION,description)
                except NotImplementedError:
                    pass    ## ChangeServiceConfig2 and description do not exist on NT

        finally:
            win32service.CloseServiceHandle(hs)
    finally:
        win32service.CloseServiceHandle(hscm)
    InstallPythonClassString(pythonClassString, serviceName)
    # If I have performance monitor info to install, do that.
    if perfMonIni is not None:
        InstallPerfmonForService(serviceName, perfMonIni, perfMonDll) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:51,代码来源:win32serviceutil.py

示例12: is_agent_running

# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import OpenSCManager [as 别名]
def is_agent_running(self, fail_if_running=False, fail_if_not_running=False):
        """Returns true if the agent service is running, as determined by this platform implementation.

        This will optionally raise an Exception with an appropriate error message if the agent is running or not
        runnning.

        @param fail_if_running:  True if the method should raise an Exception with a platform-specific error message
            explaining how it determined the agent is running.
        @param fail_if_not_running: True if the method should raise an Exception with a platform-specific error message
            explaining how it determined the agent is not running.

        @type fail_if_running: bool
        @type fail_if_not_running: bool

        @return: True if the agent process is already running.
        @rtype: bool

        @raise AgentAlreadyRunning
        @raise AgentNotRunning
        """

        hscm = None
        hs = None

        try:
            hscm = win32service.OpenSCManager(
                None, None, win32service.SC_MANAGER_CONNECT
            )
            hs = win32serviceutil.SmartOpenService(
                hscm, _SCALYR_AGENT_SERVICE_, win32service.SERVICE_QUERY_STATUS
            )
            status = win32service.QueryServiceStatusEx(hs)

            state = status["CurrentState"]

            is_running = state in (
                win32service.SERVICE_RUNNING,
                win32service.SERVICE_START_PENDING,
            )
            if fail_if_running and is_running:
                pid = status["ProcessId"]
                raise AgentAlreadyRunning(
                    "The operating system reports the Scalyr Agent Service is running with "
                    "pid=%d" % pid
                )
            if fail_if_not_running and not is_running:
                raise AgentNotRunning(
                    "The operating system reports the Scalyr Agent Service is not running"
                )

            return state in (
                win32service.SERVICE_RUNNING,
                win32service.SERVICE_START_PENDING,
            )

        finally:
            if hs is not None:
                win32service.CloseServiceHandle(hs)
            if hscm is not None:
                win32service.CloseServiceHandle(hscm) 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:62,代码来源:platform_windows.py


注:本文中的win32service.OpenSCManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。