本文整理汇总了Python中win32service.CloseServiceHandle方法的典型用法代码示例。如果您正苦于以下问题:Python win32service.CloseServiceHandle方法的具体用法?Python win32service.CloseServiceHandle怎么用?Python win32service.CloseServiceHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32service
的用法示例。
在下文中一共展示了win32service.CloseServiceHandle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RemoveService
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [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
示例2: StopServiceWithDeps
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def StopServiceWithDeps(serviceName, machine = None, waitSecs = 30):
# Stop a service recursively looking for dependant services
hscm = win32service.OpenSCManager(machine,None,win32service.SC_MANAGER_ALL_ACCESS)
try:
deps = __FindSvcDeps(serviceName)
for dep in deps:
hs = win32service.OpenService(hscm, dep, win32service.SERVICE_ALL_ACCESS)
try:
__StopServiceWithTimeout(hs, waitSecs)
finally:
win32service.CloseServiceHandle(hs)
# Now my service!
hs = win32service.OpenService(hscm, serviceName, win32service.SERVICE_ALL_ACCESS)
try:
__StopServiceWithTimeout(hs, waitSecs)
finally:
win32service.CloseServiceHandle(hs)
finally:
win32service.CloseServiceHandle(hscm)
示例3: create_service
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def create_service(self, service_name, display_name, path, start_mode,
username=None, password=None):
LOG.debug('Creating service %s', service_name)
start_type = self._get_win32_start_type(start_mode)
with WindowsUtils._get_service_control_manager(
scm_access=win32service.SC_MANAGER_CREATE_SERVICE) as hscm:
hs = win32service.CreateService(
hscm, service_name, display_name,
win32service.SERVICE_ALL_ACCESS,
win32service.SERVICE_WIN32_OWN_PROCESS,
start_type,
win32service.SERVICE_ERROR_NORMAL,
path, None, False, None,
username, password)
win32service.CloseServiceHandle(hs)
示例4: __init__
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [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
示例5: Stop
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def Stop(self):
"""
This will be called to stop the thread.
"""
if self.file:
writeOvlap = win32file.OVERLAPPED()
writeOvlap.hEvent = win32event.CreateEvent(None, 0, 0, None)
msg = "q".encode("ascii")
win32file.WriteFile(self.file, msg, writeOvlap)
win32file.CloseHandle(self.file)
self.file = None
self.keepRunning = False
if self.service:
win32service.CloseServiceHandle(self.service)
#eg.PrintNotice("MCE_Vista: stopping thread")
示例6: remove_service
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def remove_service(self, also_close_as=True):
self.session.logging.debug("Removing service %s",
self.plugin_args.service_name)
# Make sure the handle is closed.
if also_close_as:
self.session.physical_address_space.close()
# Stop the service if it's running.
if not self.hSvc:
try:
self.hSvc = win32service.OpenService(
self.hScm, self.plugin_args.service_name,
win32service.SERVICE_ALL_ACCESS)
except win32service.error:
self.session.logging.debug("%s service does not exist.",
self.plugin_args.service_name)
if self.hSvc:
self.session.logging.debug("Stopping service: %s",
self.plugin_args.service_name)
try:
win32service.ControlService(
self.hSvc, win32service.SERVICE_CONTROL_STOP)
except win32service.error as e:
self.session.logging.debug("Error stopping service: %s", e)
self.session.logging.debug("Deleting service: %s",
self.plugin_args.service_name)
try:
win32service.DeleteService(self.hSvc)
except win32service.error as e:
self.session.logging.debug("Error deleting service: %s", e)
win32service.CloseServiceHandle(self.hSvc)
示例7: InstallService
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [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)
示例8: ControlService
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [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
示例9: QueryServiceStatus
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [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
示例10: __del__
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def __del__(self):
win32service.CloseServiceHandle(self.service)
示例11: ReloadData
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def ReloadData(self):
service = self.GetSelService()
self.listCtrl.SetRedraw(0)
self.listCtrl.ResetContent()
svcs = win32service.EnumServicesStatus(self.scm)
i = 0
self.data = []
for svc in svcs:
try:
status = ('Unknown', 'Stopped', 'Starting', 'Stopping', 'Running',
'Continuing', 'Pausing', 'Paused')[svc[2][1]]
except:
status = 'Unknown'
s = win32service.OpenService(self.scm, svc[0], win32service.SERVICE_ALL_ACCESS)
cfg = win32service.QueryServiceConfig(s)
try:
startup = ('Boot', 'System', 'Automatic', 'Manual', 'Disabled')[cfg[1]]
except:
startup = 'Unknown'
win32service.CloseServiceHandle(s)
# svc[2][2] control buttons
pos = self.listCtrl.AddString(str(svc[1]) + '\t' + status + '\t' + startup)
self.listCtrl.SetItemData(pos, i)
self.data.append(tuple(svc[2]) + (svc[1], svc[0], ))
i = i + 1
if service and service[1] == svc[0]:
self.listCtrl.SetCurSel(pos)
self.OnListEvent(self.IDC_LIST, win32con.LBN_SELCHANGE)
self.listCtrl.SetRedraw(1)
示例12: OnStartCmd
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def OnStartCmd(self, id, code):
service = self.GetSelService()
if not service:
return
s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
win32service.StartService(s, None)
win32service.CloseServiceHandle(s)
self.ReloadData()
示例13: OnPauseCmd
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def OnPauseCmd(self, id, code):
service = self.GetSelService()
if not service:
return
s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
win32service.ControlService(s, win32service.SERVICE_CONTROL_PAUSE)
win32service.CloseServiceHandle(s)
self.ReloadData()
示例14: OnContinueCmd
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [as 别名]
def OnContinueCmd(self, id, code):
service = self.GetSelService()
if not service:
return
s = win32service.OpenService(self.scm, service[1], win32service.SERVICE_ALL_ACCESS)
win32service.ControlService(s, win32service.SERVICE_CONTROL_CONTINUE)
win32service.CloseServiceHandle(s)
self.ReloadData()
示例15: _get_service_control_manager
# 需要导入模块: import win32service [as 别名]
# 或者: from win32service import CloseServiceHandle [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)