110 lines
3.5 KiB
C++
110 lines
3.5 KiB
C++
/****************************** Module Header ******************************\
|
|
* Module Name: CppWindowsService.cpp
|
|
* Project: CppWindowsService
|
|
* Copyright (c) Microsoft Corporation.
|
|
*
|
|
* The file defines the entry point of the application. According to the
|
|
* arguments in the command line, the function installs or uninstalls or
|
|
* starts the service by calling into different routines.
|
|
*
|
|
* This source is subject to the Microsoft Public License.
|
|
* See http://www.microsoft.com/en-us/openness/resources/licenses.aspx#MPL.
|
|
* All other rights reserved.
|
|
*
|
|
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
|
|
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
\***************************************************************************/
|
|
|
|
#pragma region Includes
|
|
#include "SSAservice.h"
|
|
#include "ServiceInstaller.h"
|
|
#include <string>
|
|
#pragma endregion
|
|
|
|
//
|
|
// Settings of the service
|
|
//
|
|
|
|
// Internal name of the service
|
|
#define SERVICE_NAME TEXT("SSAservice")
|
|
|
|
// Displayed name of the service
|
|
#define SERVICE_DISPLAY_NAME TEXT("SSA Sirio Software Autentication")
|
|
|
|
// Service start options.
|
|
#define SERVICE_START_TYPE SERVICE_AUTO_START
|
|
|
|
// List of service dependencies - "dep1\0dep2\0\0"
|
|
#define SERVICE_DEPENDENCIES TEXT("")
|
|
|
|
// The name of the account under which the service should run
|
|
#define SERVICE_ACCOUNT TEXT("NT AUTHORITY\\LocalService")
|
|
|
|
// The password to the service account name
|
|
#define SERVICE_PASSWORD NULL
|
|
|
|
|
|
//
|
|
// FUNCTION: wmain(int, wchar_t *[])
|
|
//
|
|
// PURPOSE: entrypoint for the application.
|
|
//
|
|
// PARAMETERS:
|
|
// argc - number of command line arguments
|
|
// argv - array of command line arguments
|
|
//
|
|
// RETURN VALUE:
|
|
// none
|
|
//
|
|
// COMMENTS:
|
|
// wmain() either performs the command line task, or run the service.
|
|
//
|
|
int wmain(int argc, wchar_t *argv[])
|
|
{
|
|
if ((argc > 1) && ((*argv[1] == L'-' || (*argv[1] == L'/'))))
|
|
{
|
|
if (_wcsicmp(L"install", argv[1] + 1) == 0)
|
|
{
|
|
InstallService(
|
|
SERVICE_NAME, // Name of service
|
|
SERVICE_DISPLAY_NAME, // Name to display
|
|
SERVICE_WIN32_OWN_PROCESS,
|
|
SERVICE_START_TYPE, // Service start type
|
|
SERVICE_DEPENDENCIES, // Dependencies
|
|
SERVICE_ACCOUNT, // Service running account
|
|
SERVICE_PASSWORD // Password of the account
|
|
);
|
|
}
|
|
else if (_wcsicmp(L"remove", argv[1] + 1) == 0)
|
|
{
|
|
UninstallService(SERVICE_NAME);
|
|
}
|
|
else if (_wcsicmp(L"start", argv[1] + 1) == 0)
|
|
{
|
|
StartService(SERVICE_NAME);
|
|
}
|
|
else if (_wcsicmp(L"stop", argv[1] + 1) == 0)
|
|
{
|
|
StopService(SERVICE_NAME);
|
|
}
|
|
else if (_wcsicmp(L"restart", argv[1] + 1) == 0)
|
|
{
|
|
StopService(SERVICE_NAME);
|
|
::Sleep(1000);
|
|
StartService(SERVICE_NAME);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CSSAservice service(SERVICE_NAME);
|
|
if (!CServiceBase::Run(service))
|
|
{
|
|
wprintf(L"Parameters: -install -start -stop -restart -remove\n");
|
|
wprintf(L"Running as standard process from command line\n");
|
|
service.ServiceLoop();
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |