campo-sirio/SSAservice/ESignMain.cpp
guy d40707a134 Versione 12
git-svn-id: svn://10.65.10.50/branches/R_10_00@23098 c028cbd2-c16b-5b4b-a496-9718f37d4682
2015-05-15 09:09:10 +00:00

116 lines
3.8 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 "EsignService.h"
#include "ServiceInstaller.h"
#pragma endregion
//
// Settings of the service
//
// Internal name of the service
#define SERVICE_NAME TEXT("ESignService")
// Displayed name of the service
#define SERVICE_DISPLAY_NAME TEXT("Sirio Digital signature service")
// Service start options.
#define SERVICE_TYPE SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS
// 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")
#define SERVICE_ACCOUNT NULL
// 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)
{
if (InstallService(
SERVICE_NAME, // Name of service
SERVICE_DISPLAY_NAME, // Name to display
SERVICE_TYPE, // Service type
SERVICE_START_TYPE, // Service start type
SERVICE_DEPENDENCIES, // Dependencies
SERVICE_ACCOUNT, // Service running account
SERVICE_PASSWORD // Password of the account
))
StartService(SERVICE_NAME);
}
else if (_wcsicmp(L"remove", argv[1] + 1) == 0 || _wcsicmp(L"uninstall", 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
{
CESignService service(SERVICE_NAME);
if (!CServiceBase::Run(service))
{
printf("ESignService 1.4 %s\n", __TIMESTAMP__);
printf("Parameters: -install -start -stop -restart -remove\n");
printf("Running as standard process from command line\n");
service.ServiceLoop();
}
}
return 0;
}