mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Added ControlService + service.stop() + service.start() accept arguments
This commit is contained in:
@@ -862,76 +862,6 @@ LPVOID WINAPI MapViewOfFile(
|
||||
);
|
||||
|
||||
|
||||
SC_HANDLE WINAPI OpenSCManagerA(
|
||||
__in_opt LPCSTR lpMachineName,
|
||||
__in_opt LPCSTR lpDatabaseName,
|
||||
__in DWORD dwDesiredAccess
|
||||
);
|
||||
|
||||
SC_HANDLE WINAPI OpenSCManagerW(
|
||||
__in_opt LPCWSTR lpMachineName,
|
||||
__in_opt LPCWSTR lpDatabaseName,
|
||||
__in DWORD dwDesiredAccess
|
||||
);
|
||||
|
||||
BOOL WINAPI CloseServiceHandle(
|
||||
_In_ SC_HANDLE hSCObject
|
||||
);
|
||||
|
||||
BOOL WINAPI EnumServicesStatusExA(
|
||||
__in SC_HANDLE hSCManager,
|
||||
__in SC_ENUM_TYPE InfoLevel,
|
||||
__in DWORD dwServiceType,
|
||||
__in DWORD dwServiceState,
|
||||
_Out_opt_ LPBYTE lpServices,
|
||||
__in DWORD cbBufSize,
|
||||
__out LPDWORD pcbBytesNeeded,
|
||||
__out LPDWORD lpServicesReturned,
|
||||
__inout_opt LPDWORD lpResumeHandle,
|
||||
__in_opt LPCSTR pszGroupName
|
||||
);
|
||||
|
||||
|
||||
BOOL WINAPI EnumServicesStatusExW(
|
||||
__in SC_HANDLE hSCManager,
|
||||
__in SC_ENUM_TYPE InfoLevel,
|
||||
__in DWORD dwServiceType,
|
||||
__in DWORD dwServiceState,
|
||||
_Out_opt_ LPBYTE lpServices,
|
||||
__in DWORD cbBufSize,
|
||||
__out LPDWORD pcbBytesNeeded,
|
||||
__out LPDWORD lpServicesReturned,
|
||||
__inout_opt LPDWORD lpResumeHandle,
|
||||
__in_opt LPCWSTR pszGroupName
|
||||
);
|
||||
|
||||
|
||||
BOOL WINAPI StartServiceA(
|
||||
_In_ SC_HANDLE hService,
|
||||
_In_ DWORD dwNumServiceArgs,
|
||||
_In_opt_ LPCSTR *lpServiceArgVectors
|
||||
);
|
||||
|
||||
BOOL WINAPI StartServiceW(
|
||||
_In_ SC_HANDLE hService,
|
||||
_In_ DWORD dwNumServiceArgs,
|
||||
_In_opt_ LPCWSTR *lpServiceArgVectors
|
||||
);
|
||||
|
||||
SC_HANDLE WINAPI OpenServiceA(
|
||||
_In_ SC_HANDLE hSCManager,
|
||||
_In_ LPCSTR lpServiceName,
|
||||
_In_ DWORD dwDesiredAccess
|
||||
);
|
||||
|
||||
|
||||
SC_HANDLE WINAPI OpenServiceW(
|
||||
_In_ SC_HANDLE hSCManager,
|
||||
_In_ LPCWSTR lpServiceName,
|
||||
_In_ DWORD dwDesiredAccess
|
||||
);
|
||||
|
||||
|
||||
DWORD WINAPI GetLogicalDriveStringsA(
|
||||
_In_ DWORD nBufferLength,
|
||||
_Out_ LPCSTR lpBuffer
|
||||
|
||||
+1710
-1705
File diff suppressed because it is too large
Load Diff
@@ -93,14 +93,26 @@ class Service(object):
|
||||
class ServiceA(Service, ENUM_SERVICE_STATUS_PROCESSA):
|
||||
"""A Service object with ascii data"""
|
||||
def start(self, args=None):
|
||||
nbelt = 0
|
||||
if args is not None:
|
||||
raise NotImplementedError("Start service with args != None")
|
||||
if isinstance(args, basestring):
|
||||
args = [args]
|
||||
nbelt = len(args)
|
||||
args = (gdef.LPCSTR * (nbelt))(*args)
|
||||
|
||||
with scmanagera(SC_MANAGER_CONNECT) as scm:
|
||||
# windows.winproxy.StartServiceA()
|
||||
servh = windows.winproxy.OpenServiceA(scm, self.name, SERVICE_START)
|
||||
windows.winproxy.StartServiceA(servh, 0, None)
|
||||
windows.winproxy.StartServiceA(servh, nbelt, args)
|
||||
windows.winproxy.CloseServiceHandle(servh)
|
||||
|
||||
def stop(self):
|
||||
status = SERVICE_STATUS()
|
||||
with scmanagera(SC_MANAGER_CONNECT) as scm:
|
||||
servh = windows.winproxy.OpenServiceA(scm, self.name, SERVICE_STOP)
|
||||
windows.winproxy.ControlService(servh, SERVICE_CONTROL_STOP, status)
|
||||
windows.winproxy.CloseServiceHandle(servh)
|
||||
return status
|
||||
|
||||
|
||||
@contextmanager
|
||||
def scmanagera(access):
|
||||
|
||||
@@ -379,6 +379,10 @@ def OpenServiceA(hSCManager, lpServiceName, dwDesiredAccess):
|
||||
def OpenServiceW(hSCManager, lpServiceName, dwDesiredAccess):
|
||||
return OpenServiceW.ctypes_function(hSCManager, lpServiceName, dwDesiredAccess)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ControlService(hService, dwControl, lpServiceStatus):
|
||||
return ControlService.ctypes_function(hService, dwControl, lpServiceStatus)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CloseServiceHandle(hSCObject):
|
||||
return CloseServiceHandle.ctypes_function(hSCObject)
|
||||
|
||||
Reference in New Issue
Block a user