install windows service with daemon argument

This commit is contained in:
R4SAS 2017-07-10 01:14:55 +03:00
parent 6d259e00a3
commit 641ca3d49d

View file

@ -70,7 +70,6 @@ void WINAPI I2PService::ServiceCtrlHandler(DWORD dwCtrl)
} }
} }
I2PService::I2PService(PSTR pszServiceName, I2PService::I2PService(PSTR pszServiceName,
BOOL fCanStop, BOOL fCanStop,
BOOL fCanShutdown, BOOL fCanShutdown,
@ -147,8 +146,7 @@ void I2PService::Start(DWORD dwArgc, PSTR *pszArgv)
void I2PService::OnStart(DWORD dwArgc, PSTR *pszArgv) void I2PService::OnStart(DWORD dwArgc, PSTR *pszArgv)
{ {
LogPrint(eLogInfo, "Win32Service in OnStart", LogPrint(eLogInfo, "Win32Service in OnStart", EVENTLOG_INFORMATION_TYPE);
EVENTLOG_INFORMATION_TYPE);
Daemon.start(); Daemon.start();
@ -165,7 +163,7 @@ void I2PService::WorkerThread()
{ {
while (!m_fStopping) while (!m_fStopping)
{ {
::Sleep(1000); // Simulate some lengthy operations. ::Sleep(1000); // Simulate some lengthy operations.
} }
// Signal the stopped event. // Signal the stopped event.
@ -270,12 +268,10 @@ void I2PService::Continue()
} }
} }
void I2PService::OnContinue() void I2PService::OnContinue()
{ {
} }
void I2PService::Shutdown() void I2PService::Shutdown()
{ {
try try
@ -294,19 +290,16 @@ void I2PService::Shutdown()
} }
} }
void I2PService::OnShutdown() void I2PService::OnShutdown()
{ {
} }
void I2PService::SetServiceStatus(DWORD dwCurrentState, void I2PService::SetServiceStatus(DWORD dwCurrentState,
DWORD dwWin32ExitCode, DWORD dwWin32ExitCode,
DWORD dwWaitHint) DWORD dwWaitHint)
{ {
static DWORD dwCheckPoint = 1; static DWORD dwCheckPoint = 1;
m_status.dwCurrentState = dwCurrentState; m_status.dwCurrentState = dwCurrentState;
m_status.dwWin32ExitCode = dwWin32ExitCode; m_status.dwWin32ExitCode = dwWin32ExitCode;
m_status.dwWaitHint = dwWaitHint; m_status.dwWaitHint = dwWaitHint;
@ -335,12 +328,7 @@ void FreeHandles(SC_HANDLE schSCManager, SC_HANDLE schService)
} }
} }
void InstallService(PSTR pszServiceName, void InstallService(PSTR pszServiceName, PSTR pszDisplayName, DWORD dwStartType, PSTR pszDependencies, PSTR pszAccount, PSTR pszPassword)
PSTR pszDisplayName,
DWORD dwStartType,
PSTR pszDependencies,
PSTR pszAccount,
PSTR pszPassword)
{ {
printf("Try to install Win32Service (%s).\n", pszServiceName); printf("Try to install Win32Service (%s).\n", pszServiceName);
@ -354,10 +342,10 @@ void InstallService(PSTR pszServiceName,
FreeHandles(schSCManager, schService); FreeHandles(schSCManager, schService);
return; return;
} }
strncat(szPath, " --daemon", MAX_PATH);
// Open the local default service control manager database // Open the local default service control manager database
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE);
SC_MANAGER_CREATE_SERVICE);
if (schSCManager == NULL) if (schSCManager == NULL)
{ {
printf("OpenSCManager failed w/err 0x%08lx\n", GetLastError()); printf("OpenSCManager failed w/err 0x%08lx\n", GetLastError());
@ -381,6 +369,7 @@ void InstallService(PSTR pszServiceName,
pszAccount, // Service running account pszAccount, // Service running account
pszPassword // Password of the account pszPassword // Password of the account
); );
if (schService == NULL) if (schService == NULL)
{ {
printf("CreateService failed w/err 0x%08lx\n", GetLastError()); printf("CreateService failed w/err 0x%08lx\n", GetLastError());
@ -412,8 +401,7 @@ void UninstallService(PSTR pszServiceName)
} }
// Open the service with delete, stop, and query status permissions // Open the service with delete, stop, and query status permissions
schService = OpenService(schSCManager, pszServiceName, SERVICE_STOP | schService = OpenService(schSCManager, pszServiceName, SERVICE_STOP | SERVICE_QUERY_STATUS | DELETE);
SERVICE_QUERY_STATUS | DELETE);
if (schService == NULL) if (schService == NULL)
{ {
printf("OpenService failed w/err 0x%08lx\n", GetLastError()); printf("OpenService failed w/err 0x%08lx\n", GetLastError());