Giter Site home page Giter Site logo

windowsservice's Introduction

WindowsService

Class manage Windows Service - Install, Uninstall, Start, Stop action. I modify and combine from 2 source code

  1. https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948
  2. https://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus

Tested in Visual Studio 2017, 64bit platform and Unicode Character Set.

Getting Started

  1. Create new project name is "SampleService", project type is "Windows Console Application"
  2. add WindowsService.cpp and WindowsService.h in your project
  3. Write script below
#include "stdafx.h"
#include "WindowsService.h"

void serve()
{
   //your logic application
}

int wmain(int argc, wchar_t *argv[])
{
	const wchar_t* serviceName = _T("SampleService");
	const wchar_t* displayName = _T("Sample Service");
	const wchar_t* serviceDependencies = _T("");
	const wchar_t* serviceAccount = _T("NT AUTHORITY\\LocalService");
	const wchar_t* servicePassword = NULL;
	int status = EXIT_FAILURE;

	//run the main service
	return Windows::Service::Main(
		serviceName,
		displayName,
		SERVICE_DEMAND_START,
		serviceDependencies,
		serviceAccount,
		servicePassword,
		serve,
		argc,
		argv);
}

  1. Change project to 64bit platform.
  2. Build project. Output at /x64/SampleService.exe
  3. Open Console Prompt. (run as administrator)
  4. SampleService.exe -install
  5. SampleService.exe - remove
  6. net start SampleService
  7. net stop SampleService

windowsservice's People

Contributors

syukrimokhtar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.