Initial
This commit is contained in:
52
watchdog/ServiceControlManager.hpp
Normal file
52
watchdog/ServiceControlManager.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef _WATCHDOG_SERVICECONTROLMANAGER_HPP_
|
||||
#define _WATCHDOG_SERVICECONTROLMANAGER_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _WATCHDOG_SERVICEHANDLE_HPP_
|
||||
#include <watchdog/ServiceHandle.hpp>
|
||||
#endif
|
||||
#ifndef _WATCHDOG_CREATESERVICEPARAMS_HPP_
|
||||
#include <watchdog/CreateServiceParams.hpp>
|
||||
#endif
|
||||
|
||||
class ServiceControlManager
|
||||
{
|
||||
public:
|
||||
enum Access{Connect=SC_MANAGER_CONNECT,Enumerate=SC_MANAGER_ENUMERATE_SERVICE,QueryLock=SC_MANAGER_QUERY_LOCK_STATUS,
|
||||
ModifyBootConfig=SC_MANAGER_MODIFY_BOOT_CONFIG,StandardRightsRead=STANDARD_RIGHTS_READ,
|
||||
StandardRightsWrite=STANDARD_RIGHTS_WRITE,StandardRightsExecute=STANDARD_RIGHTS_EXECUTE,
|
||||
AllAccess=SC_MANAGER_ALL_ACCESS,CreateService=SC_MANAGER_CREATE_SERVICE,
|
||||
Lock=SC_MANAGER_LOCK};
|
||||
ServiceControlManager(Access access=AllAccess,const String &machineName=String(),const String &databaseName=String());
|
||||
virtual ~ServiceControlManager();
|
||||
bool createService(CreateServiceParams &csp,ServiceHandle &serviceHandle);
|
||||
bool deleteService(const String &serviceName);
|
||||
bool startService(const String &serviceName,Block<String> &serviceArgs=Block<String>());
|
||||
bool isOkay(void)const;
|
||||
String getLastErrorCode(void)const;
|
||||
private:
|
||||
ServiceHandle mServiceHandle;
|
||||
DWORD mLastError;
|
||||
};
|
||||
|
||||
inline
|
||||
ServiceControlManager::ServiceControlManager(Access access,const String &machineName,const String &databaseName)
|
||||
: mLastError(0)
|
||||
{
|
||||
mServiceHandle.setHandle(::OpenSCManager(machineName.isNull()?(char*)0:machineName.str(),databaseName.isNull()?(char*)0:databaseName.str(),access),ServiceHandle::Delete);
|
||||
if(!mServiceHandle.isOkay())mLastError=::GetLastError();
|
||||
}
|
||||
|
||||
inline
|
||||
ServiceControlManager::~ServiceControlManager()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
bool ServiceControlManager::isOkay(void)const
|
||||
{
|
||||
return mServiceHandle.isOkay();
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user