mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Renamed NewService class as Service + updated doc/sample for new service API
This commit is contained in:
@@ -39,4 +39,10 @@ class _SERVICE_STATUS_PROCESS(_SERVICE_STATUS_PROCESS):
|
||||
state = dwCurrentState
|
||||
type = dwServiceType
|
||||
control_accepted = dwControlsAccepted
|
||||
flags = dwServiceFlags
|
||||
flags = dwServiceFlags
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return """<{0} type={1!r} state={2!r}>""".format(type(self).__name__,
|
||||
self.type,
|
||||
self.state)
|
||||
@@ -0,0 +1,19 @@
|
||||
(cmd) python service\service_demo.py
|
||||
Listing the first 3 services:
|
||||
* <Service "1394ohci" SERVICE_STOPPED(0x1)>
|
||||
* <Service "3ware" SERVICE_STOPPED(0x1)>
|
||||
* <Service "ACPI" SERVICE_RUNNING(0x4)>
|
||||
|
||||
Retriving service <TapiSrv>
|
||||
<Service "TapiSrv" SERVICE_STOPPED(0x1)>
|
||||
- name: 'TapiSrv'
|
||||
- description: 'Telephony'
|
||||
- state: SERVICE_STOPPED(0x1)
|
||||
- type: 48L
|
||||
- process: None
|
||||
- security-description: O:SYG:SYD:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPLOCRRC;;;IU)(A;;CCLCSWRPLOCRRC;;;SU)
|
||||
Trying to start the service
|
||||
Service started !
|
||||
<Service "TapiSrv" SERVICE_RUNNING(0x4)>
|
||||
- state: SERVICE_RUNNING(0x4)
|
||||
- process: <WinProcess "!cannot-retrieve-name" pid 14700 at 0x4a2c4f0>
|
||||
@@ -3,45 +3,45 @@ Basic system infos:
|
||||
version = (10, 0)
|
||||
bitness = 64
|
||||
computer_name = WILLIE
|
||||
product_type = VER_NT_WORKSTATION(0x1L)
|
||||
product_type = 1
|
||||
version_name = Windows 10
|
||||
|
||||
There is 194 processes
|
||||
There is 2324 threads
|
||||
There is 331 processes
|
||||
There is 4010 threads
|
||||
|
||||
Dumping first logical drive:
|
||||
<LogicalDrive "C:\" (DRIVE_FIXED)>
|
||||
name = C:\
|
||||
type = DRIVE_FIXED(0x3L)
|
||||
path = \Device\HarddiskVolume2
|
||||
<LogicalDrive "B:\" (DRIVE_FIXED)>
|
||||
name = B:\
|
||||
type = 3
|
||||
path = \Device\HarddiskVolume7
|
||||
|
||||
Dumping first service:
|
||||
<ServiceA "1394ohci" SERVICE_STOPPED(0x1L)>
|
||||
<Service "1394ohci" SERVICE_STOPPED(0x1)>
|
||||
name = 1394ohci
|
||||
description = 1394 OHCI Compliant Host Controller
|
||||
status = ServiceStatus(type=SERVICE_KERNEL_DRIVER(0x1L), state=SERVICE_STOPPED(0x1L), control_accepted=0L, flags=0L)
|
||||
status = <_SERVICE_STATUS_PROCESS type=SERVICE_KERNEL_DRIVER(0x1) state=SERVICE_STOPPED(0x1)>
|
||||
process = None
|
||||
|
||||
Finding a service in a user process:
|
||||
<ServiceA "AppIDSvc" SERVICE_RUNNING(0x4L)>
|
||||
<Service "AppIDSvc" SERVICE_RUNNING(0x4)>
|
||||
name = AppIDSvc
|
||||
description = Application Identity
|
||||
status = ServiceStatus(type=48L, state=SERVICE_RUNNING(0x4L), control_accepted=5L, flags=0L)
|
||||
process = <WinProcess "!cannot-retrieve-name" pid 7076 at 0x631eb70>
|
||||
status = <_SERVICE_STATUS_PROCESS type=48L state=SERVICE_RUNNING(0x4)>
|
||||
process = <WinProcess "!cannot-retrieve-name" pid 6060 at 0x35851d0>
|
||||
|
||||
Enumerating handles:
|
||||
There are 78079 handles:
|
||||
First handle is: <Handle value=<0x4> in process pid=4>
|
||||
There are 208332 handles:
|
||||
First handle is: <HandleWow64 value=<0x4> in process pid=4>
|
||||
Enumerating handles of the current process:
|
||||
There are 260 handles for this process
|
||||
There are 275 handles for this process
|
||||
Looking for a File handle:
|
||||
Handle is <Handle value=<0x4> in process pid=10968>
|
||||
Handle is <HandleWow64 value=<0x4> in process pid=15236>
|
||||
Name is <\Device\ConDrv>
|
||||
|
||||
Dumping the first system module
|
||||
<SystemModuleWow64 name="\SystemRoot\system32\ntoskrnl.exe" base=0xfffff803f9697000>
|
||||
<SystemModuleWow64 name="\SystemRoot\system32\ntoskrnl.exe" base=0xfffff80023000000>
|
||||
ImageName = \SystemRoot\system32\ntoskrnl.exe
|
||||
Base = 0xfffff803f9697000
|
||||
Size = 0x8d5000
|
||||
Base = 0xfffff80023000000
|
||||
Size = 0xab7000
|
||||
Flags = 0x8804000
|
||||
LoadCount = 139
|
||||
LoadCount = 240
|
||||
|
||||
+14
-2
@@ -1,7 +1,7 @@
|
||||
Service
|
||||
=======
|
||||
|
||||
The list of services is accessible via :py:attr:`windows.system.services
|
||||
The services manager is accessible via :py:attr:`windows.system.services
|
||||
<windows.winobject.system.System.services>`
|
||||
|
||||
.. note::
|
||||
@@ -10,6 +10,18 @@ The list of services is accessible via :py:attr:`windows.system.services
|
||||
|
||||
.. module:: windows.winobject.service
|
||||
|
||||
.. autoclass:: Service
|
||||
|
||||
ServiceManager
|
||||
""""""""""""""
|
||||
|
||||
.. autoclass:: ServiceManager
|
||||
:show-inheritance:
|
||||
:inherited-members:
|
||||
:special-members: __getitem__, __iter__
|
||||
|
||||
|
||||
Service
|
||||
"""""""
|
||||
|
||||
.. autoclass:: Service
|
||||
:inherited-members:
|
||||
@@ -39,6 +39,7 @@ from windows.pycompat import basestring
|
||||
|
||||
|
||||
class ServiceManager(utils.AutoHandle):
|
||||
"""An object to query, list and explore services"""
|
||||
def _get_handle(self):
|
||||
return windows.winproxy.OpenSCManagerA(dwDesiredAccess=gdef.MAXIMUM_ALLOWED)
|
||||
|
||||
@@ -46,6 +47,10 @@ class ServiceManager(utils.AutoHandle):
|
||||
return windows.winproxy.OpenServiceA(self.handle, name, access) # Check service exists :)
|
||||
|
||||
def get_service(self, key, access=gdef.MAXIMUM_ALLOWED):
|
||||
"""Get a service by its name/index or a list of services via a slice
|
||||
|
||||
:return: :class:`Service` or [:class:`Service`] -- A :class:`Service` or list of :class:`Service`
|
||||
"""
|
||||
if isinstance(key, int_types):
|
||||
return self.enumerate_services()[key]
|
||||
if isinstance(key, slice):
|
||||
@@ -59,6 +64,10 @@ class ServiceManager(utils.AutoHandle):
|
||||
return Service(name=key, handle=handle)
|
||||
|
||||
__getitem__ = get_service
|
||||
"""Get a service by its name/index or a list of services via a slice
|
||||
|
||||
:return: :class:`Service` or [:class:`Service`] -- A :class:`Service` or list of :class:`Service`
|
||||
"""
|
||||
|
||||
def get_service_display_name(self, name):
|
||||
# This API is strange..
|
||||
@@ -70,6 +79,9 @@ class ServiceManager(utils.AutoHandle):
|
||||
return result.value
|
||||
|
||||
def _enumerate_services_generator(self):
|
||||
"""The generator code behind __iter__.
|
||||
Allow to iter over the services on the system
|
||||
"""
|
||||
size_needed = gdef.DWORD()
|
||||
nb_services = gdef.DWORD()
|
||||
counter = gdef.DWORD()
|
||||
@@ -93,12 +105,17 @@ class ServiceManager(utils.AutoHandle):
|
||||
return
|
||||
|
||||
__iter__ = _enumerate_services_generator
|
||||
"""Iter over the services on the system
|
||||
|
||||
:yield: :class:`Service`
|
||||
"""
|
||||
|
||||
def enumerate_services(self):
|
||||
return list(self._enumerate_services_generator())
|
||||
|
||||
|
||||
class Service(gdef.SC_HANDLE):
|
||||
"""Represent a service on the system"""
|
||||
def __init__(self, handle, name, description=None):
|
||||
super(Service, self).__init__(handle)
|
||||
self.name = name
|
||||
@@ -149,6 +166,10 @@ class Service(gdef.SC_HANDLE):
|
||||
return security.SecurityDescriptor.from_service(self.name)
|
||||
|
||||
def start(self, args=None):
|
||||
"""Start the service
|
||||
|
||||
:param args: a list of :class:`str`
|
||||
"""
|
||||
nbelt = 0
|
||||
if args is not None:
|
||||
if isinstance(args, windows.pycompat.anybuff):
|
||||
@@ -158,6 +179,7 @@ class Service(gdef.SC_HANDLE):
|
||||
return windows.winproxy.StartServiceA(self, nbelt, args)
|
||||
|
||||
def stop(self):
|
||||
"""Stop the service"""
|
||||
status = SERVICE_STATUS()
|
||||
windows.winproxy.ControlService(self, gdef.SERVICE_CONTROL_STOP, status)
|
||||
return status
|
||||
|
||||
@@ -64,9 +64,10 @@ class System(object):
|
||||
|
||||
@utils.fixedpropety
|
||||
def services(self):
|
||||
"""The list of services
|
||||
"""An object to query, list and explore services
|
||||
|
||||
:type: [:class:`~windows.winobject.service.ServiceA`] -- A list of Service"""
|
||||
:type: :class:`~windows.winobject.service.ServiceManager`
|
||||
"""
|
||||
return service.ServiceManager()
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user