Click here to Skip to main content
13,139,569 members (49,800 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 11 Jan 2011

Create a service

, 15 Jan 2011
Rate this:
Please Sign up or sign in to vote.
This tip shows how to create a service
#include <windows.h>
#include <stdio.h>
BOOL CreateSampleService(LPCTSTR lpszDisplayName, LPCTSTR szPath)
    TCHAR szPath[MAX_PATH];
    if( !GetModuleFileName( NULL, szPath, MAX_PATH ) )
        printf("GetModuleFileName failed (%d)\n", GetLastError());
        return FALSE;
    schService = CreateService(
        schSCManager,              // SCManager database
        TEXT("Sample_Srv"),        // name of service
        lpszDisplayName,           // service name to display
        SERVICE_ALL_ACCESS,        // desired access
        SERVICE_WIN32_OWN_PROCESS, // service type
        SERVICE_DEMAND_START,      // start type
        SERVICE_ERROR_NORMAL,      // error control type
        szPath,                    // path to service's binary
        NULL,                      // no load ordering group
        NULL,                      // no tag identifier
        NULL,                      // no dependencies
        NULL,                      // LocalSystem account
        NULL);                     // no password
    if (schService == NULL)
        printf("CreateService failed (%d)\n", GetLastError());
        return FALSE;
        return TRUE;

To find out how to write a service, this site may come in handy:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mukit, Ataul
Chief Technology Officer Rational Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 1 Not an article. Pin
brianbacon15-Jan-11 15:09
memberbrianbacon15-Jan-11 15:09 
GeneralRe: You are right.. it's not an article.. it's a tip.. and the b... Pin
Mukit, Ataul16-Jan-11 17:53
memberMukit, Ataul16-Jan-11 17:53 
GeneralAdded the pre tab for you... Pin
Steve Maier13-Jan-11 7:45
memberSteve Maier13-Jan-11 7:45 
GeneralRe: How very nice.. thnx.. Pin
Mukit, Ataul15-Jan-11 17:52
memberMukit, Ataul15-Jan-11 17:52 
GeneralI tried, doesn't seem to work.. the pre tag.. Pin
Mukit, Ataul13-Jan-11 1:21
memberMukit, Ataul13-Jan-11 1:21 
GeneralReason for my vote of 1 Do I really need to explain on this ... Pin
Marcus Kramer12-Jan-11 13:41
memberMarcus Kramer12-Jan-11 13:41 
GeneralReason for my vote of 1 c&ping code from MSDN is not a tip. Pin
SledgeHammer0112-Jan-11 4:55
memberSledgeHammer0112-Jan-11 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 16 Jan 2011
Article Copyright 2011 by Mukit, Ataul
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid