1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #pragma once
- #include <windows.h>
- #include <winsvc.h>
- #include <winioctl.h>
- #ifndef _CTYPE_DISABLE_MACROS
- #define _CTYPE_DISABLE_MACROS
- #endif
- const int MAX_ERR_MSG_SIZE = 256;
- const char SERVICE_WWAN_AutoConfig[] = "WwanSvc";
- struct LastErrorInfo
- {
- DWORD dwErrMsgLen;
- DWORD dwLastErrCode;
- char szErrMsg[MAX_ERR_MSG_SIZE];
- };
- enum ServiceStatus
- {
- SERVICE_STATUS_UNKNOWN,
- SERVICE_STATUS_RUNNING,
- SERVICE_STATUS_STOPPED,
- SERVICE_STATUS_PASUSED
- };
- class CSvcManager
- {
- public:
- static CSvcManager* GetInstance();
- public:
-
- ~CSvcManager(void);
- BOOLEAN Init();
- BOOLEAN Release();
- BOOLEAN InstallService(LPCTSTR szSrvName, LPCTSTR szServiceExe);
- /*
- The name of the service to be opened.
- This is the name specified by the lpServiceName parameter of the CreateService function when the service
- object was created, not the service display name that is shown by user interface applications to identify
- the service.
- */
- BOOLEAN StartServiceWith(LPCTSTR szSrvName);
- BOOLEAN StopService(LPCTSTR szSrvName);
- BOOLEAN RemoveService(LPCTSTR szSrvName);
- BOOLEAN QueryServiceStatus(LPCTSTR szSrvName, ServiceStatus& status);
- BOOLEAN StopDependentServices(LPCTSTR szSrvName);
- void GetLastErrMsg(LastErrorInfo& lastInfo);
-
- BOOLEAN RaiseUpPrivileges();
- private:
-
- static CSvcManager* m_pInstance;
- SC_HANDLE m_schSCManager;
- BOOLEAN m_bInit;
- LastErrorInfo m_LastErrInfo;
- CSvcManager(void);
- void SaveLastErrMsg(LPCTSTR fmt, ...);
- void CoverLastErrMsg()
- {
- m_LastErrInfo.dwErrMsgLen = strlen("Last Operation succ.");
- memset(m_LastErrInfo.szErrMsg, 0, sizeof(CHAR)*MAX_ERR_MSG_SIZE);
- memcpy_s(m_LastErrInfo.szErrMsg, MAX_ERR_MSG_SIZE,
- "Last Operation succ.", strlen("Last Operation succ."));
- m_LastErrInfo.dwLastErrCode = 0;
- }
- BOOLEAN SetPrivilege(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege);
- };
|