forked from microsoftarchive/msdn-code-gallery-microsoft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Terry Fei (Pactera)
committed
Nov 25, 2019
1 parent
89a815e
commit 13bca13
Showing
740 changed files
with
34,338 additions
and
4,593 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
334 changes: 334 additions & 0 deletions
334
OneCodeTeam/A basic Windows service in C++ (CppWindowsService) 2/README.md
Large diffs are not rendered by default.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...ice) 2/[C++]-A basic Windows service in C++ (CppWindowsService)/C++/CppWindowsService.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppWindowsService", "CppWindowsService\CppWindowsService.vcxproj", "{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}" | ||
EndProject | ||
Global | ||
|
||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Win32 = Debug|Win32 | ||
Debug|x64 = Debug|x64 | ||
Release|Win32 = Release|Win32 | ||
Release|x64 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Debug|Win32.ActiveCfg = Debug|Win32 | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Debug|Win32.Build.0 = Debug|Win32 | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Debug|x64.ActiveCfg = Debug|x64 | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Debug|x64.Build.0 = Debug|x64 | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Release|Win32.ActiveCfg = Release|Win32 | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Release|Win32.Build.0 = Release|Win32 | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Release|x64.ActiveCfg = Release|x64 | ||
{DE70E2D1-6A4D-4984-BD82-CE750889F0D3}.Release|x64.Build.0 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
104 changes: 104 additions & 0 deletions
104
...ic Windows service in C++ (CppWindowsService)/C++/CppWindowsService/CppWindowsService.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/****************************** 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 <stdio.h> | ||
#include <windows.h> | ||
#include "ServiceInstaller.h" | ||
#include "ServiceBase.h" | ||
#include "SampleService.h" | ||
#pragma endregion | ||
|
||
|
||
// | ||
// Settings of the service | ||
// | ||
|
||
// Internal name of the service | ||
#define SERVICE_NAME L"CppWindowsService" | ||
|
||
// Displayed name of the service | ||
#define SERVICE_DISPLAY_NAME L"CppWindowsService Sample Service" | ||
|
||
// Service start options. | ||
#define SERVICE_START_TYPE SERVICE_DEMAND_START | ||
|
||
// List of service dependencies - "dep1\0dep2\0\0" | ||
#define SERVICE_DEPENDENCIES L"" | ||
|
||
// The name of the account under which the service should run | ||
#define SERVICE_ACCOUNT L"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) | ||
{ | ||
// Install the service when the command is | ||
// "-install" or "/install". | ||
InstallService( | ||
SERVICE_NAME, // Name of service | ||
SERVICE_DISPLAY_NAME, // Name to display | ||
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) | ||
{ | ||
// Uninstall the service when the command is | ||
// "-remove" or "/remove". | ||
UninstallService(SERVICE_NAME); | ||
} | ||
} | ||
else | ||
{ | ||
wprintf(L"Parameters:\n"); | ||
wprintf(L" -install to install the service.\n"); | ||
wprintf(L" -remove to remove the service.\n"); | ||
|
||
CSampleService service(SERVICE_NAME); | ||
if (!CServiceBase::Run(service)) | ||
{ | ||
wprintf(L"Service failed to run w/err 0x%08lx\n", GetLastError()); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.