Initial
This commit is contained in:
50
watchdog/main.cpp
Normal file
50
watchdog/main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <common/windows.hpp>
|
||||
#include <common/string.hpp>
|
||||
#include <common/winsvc.hpp>
|
||||
#include <common/file.hpp>
|
||||
#include <thread/event.hpp>
|
||||
#include <WatchDog/WatchDogService.hpp>
|
||||
#include <WatchDog/Evaluator.hpp>
|
||||
|
||||
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
|
||||
{
|
||||
ServiceControlManager serviceControlManager;
|
||||
ServiceHandle service;
|
||||
CreateServiceParams createServiceParams;
|
||||
String strPathBinaryFile;
|
||||
String strCommandLine;
|
||||
String serviceName;
|
||||
String serviceDisplayName;
|
||||
|
||||
serviceName="WatchDog";
|
||||
serviceDisplayName="WatchDog Service";
|
||||
strCommandLine=lpszCmdLine;
|
||||
if(strCommandLine=="register")
|
||||
{
|
||||
String strDependencies;
|
||||
// strDependencies="MSSQLServer"; do a better job with this one.
|
||||
::GetModuleFileName(::GetModuleHandle(0),strPathBinaryFile,String::MaxString);
|
||||
createServiceParams.setServiceName(serviceName);
|
||||
createServiceParams.setDisplayName(serviceDisplayName);
|
||||
createServiceParams.setDesiredAccess(SERVICE_ALL_ACCESS);
|
||||
createServiceParams.setServiceType(SERVICE_WIN32_OWN_PROCESS);
|
||||
createServiceParams.setStartType(SERVICE_AUTO_START);
|
||||
createServiceParams.setErrorControl(SERVICE_ERROR_IGNORE);
|
||||
createServiceParams.setBinaryPathName(strPathBinaryFile);
|
||||
createServiceParams.setDependencies(strDependencies);
|
||||
if(!serviceControlManager.createService(createServiceParams,service))
|
||||
::OutputDebugString(serviceControlManager.getLastErrorCode()+String("\n"));
|
||||
}
|
||||
else if(strCommandLine=="unregister")
|
||||
{
|
||||
if(!serviceControlManager.deleteService(serviceName))
|
||||
::OutputDebugString(serviceControlManager.getLastErrorCode()+String("\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
WatchDogService service;
|
||||
service.startServiceControlDispatcher(serviceName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user