6 #ifndef _INC_cNTService_H
7 #define _INC_cNTService_H
12 #include "../GrayLibBase.h"
14 #if defined(_WIN32) && !defined(UNDER_CE)
25 ::CloseServiceHandle(h);
31 class GRAYLIB_LINK cNTServiceHandle :
public cHandlePtr < SC_HANDLE >
38 typedef cHandlePtr<SC_HANDLE> SUPER_t;
41 : cHandlePtr<SC_HANDLE>(hSC)
47 bool QueryServiceConfigX(QUERY_SERVICE_CONFIG* pCfg, DWORD dwSizeCfgMax, DWORD& rdwSizeCfgRet)
const
50 if (!
_FNF(::QueryServiceConfig)(get_Handle(), pCfg, dwSizeCfgMax, &rdwSizeCfgRet))
56 return ::DeleteService(get_Handle());
58 bool ControlService(DWORD dwControl = SERVICE_CONTROL_STOP, LPSERVICE_STATUS lpServiceStatus =
nullptr)
60 return ::ControlService(get_Handle(), dwControl, lpServiceStatus) ? true :
false;
62 bool OpenServiceX(SC_HANDLE hSCMgr,
const FILECHAR_t* pszServiceName, DWORD dwDesiredAccess = SERVICE_ALL_ACCESS)
65 AttachHandle(
_FNF(::OpenService)(hSCMgr, pszServiceName, dwDesiredAccess));
66 return(isValidHandle());
70 class GRAYLIB_LINK cNTServiceMgr :
public cNTServiceHandle
78 cNTServiceMgr(
const FILECHAR_t* lpMachineName =
nullptr,
const FILECHAR_t* lpDatabaseName =
nullptr, DWORD dwDesiredAccess = SC_MANAGER_ALL_ACCESS)
79 : cNTServiceHandle(
_FNF(::OpenSCManager)(lpMachineName, lpDatabaseName, dwDesiredAccess))
86 void OpenServiceMgr(
const FILECHAR_t* lpMachineName =
nullptr,
const FILECHAR_t* lpDatabaseName =
nullptr, DWORD dwDesiredAccess = SC_MANAGER_ALL_ACCESS)
89 AttachHandle(
_FNF(::OpenSCManager)(lpMachineName, lpDatabaseName, dwDesiredAccess));
91 SC_HANDLE OpenServiceX(
const FILECHAR_t* pszServiceName, DWORD dwDesiredAccess = SERVICE_ALL_ACCESS)
const
97 return(
_FNF(::OpenService)(get_Handle(), pszServiceName, dwDesiredAccess));
99 bool OpenServiceX(cNTServiceHandle& sh,
const FILECHAR_t* pszServiceName, DWORD dwDesiredAccess = SERVICE_ALL_ACCESS)
const
104 sh.AttachHandle( OpenServiceX(pszServiceName, dwDesiredAccess));
105 return(sh.isValidHandle());
#define _FNF(c)
_WIN32 name has a A or W for UTF8 or UNICODE
Definition: FileName.h:24
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define HANDLE_NULL
Invalid OS handle for _WIN32. Not invalid OS handle for linux.
Definition: cOSHandle.h:21
void CloseHandle()
Definition: cHandlePtr.h:79
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22