Virtual Developer Workshop: Containerized Development with Docker

Environment: CSysService was developed for Microsoft. Windows NT. platforms using Microsoft. VisualC++ 6.0

Microsoft. Windows NT. supports a service application type which conforms to the interface rules of the Service Control Manager (SCM). Services can be installed, configured and controlled by applications using the service functions included in the Microsoft. Win32. application programming interface (API).

CSysService is a C++ class which wraps methods around several of the Win32. API service functions, providing an object-oriented interface to these functions, grouping common variables and structures in a single class object. The result is an extensible base class capable of installing, enumerating, modifying, controlling and removing a service application in the Service Control Manager.

The CSysService class can be extended (sub-classed) to enhance its capabilities. Refer to the Microsoft Platform SDK: DLLs, Processes, and Threads documentation from the MSDN (support.microsoft.com).

CSysService contains the following methods, fully documented in the download file.

     Method  Function
      Initializes the class.
      Control   Stop, continue or pause a service.
      Error   Get error code.
      ErrorMessage   Translate an error code.
      GetServiceInformation   Sets g_ServiceName.
      LocalHostName   Get name of local host computer.
      NewService   Create a new service
      Open   Opens a connection to the SCM on the specified host.
      RemoveService   Remove a service
      Result   Get operation result.
      ServiceDisplayName   Returns service's display name.
      ServiceError   Get service error code.
      ServiceErrorMessage   Translate a service error code.
      ServiceHostName   Returns connected host name.
      ServiceName   Get a service name.
      ServiceStartName   Returns account service started under.
      ServiceState   Return current service state.
      ServiceType   Get type of service.
      SetAccount   Set service start account.
      SetDisplayName   Set service display name.
      SetErrorControl   Set error control code.
      SetPassword   Set password for a service.
      SetPath   Set path to a service.
      SetServiceConfig   Apply modifications.
      SetServiceName   Set a service name.
      SetServiceType   Set service type.
      SetStartType   Set start type.
      StartType   Get startup type.
      StartupString   Translate a service startup code.
      StatusString   Translate a service status code.
      ServiceConfig   Pointer to QUERY_SERVICE_CONFIG structure.
      ServiceStatus   Pointer to SERVICE_STATUS structure.

Sample Application

Click here for larger image

NTServiceSetup is a Microsoft. Windows NT. program to manage service applications in the Service Control Manager database.


  • Create, modify, control and remove service applications.

  • VisualC++ project and source code.
  • Based on CSysService class.
  • Allows creation of parameter registry entries for use with Microsoft's SrvAny.

Double-clicking (or selecting and pressing Enter) on a row in the list will display the service properties in an edit dialog window. Selecting the add button will display an empty edit dialog window to allow a new service to be added.

NTServiceSetup was originally part of a larger Windows NT. console-based control application project. The modularity employed in the design of the control application allowed extraction of NTServiceSetup to a stand alone executable program.

NTServiceSetup can only access the host upon which it is running. However, since it is based upon the CSysService class, this functionality can be easily added.


The algorithms for creating and sorting the treeview control in this project are based on those presented by Sardaukar in his article titled "NT Simple Service Manager", also on CodeGuru.


Download demo project - 258 Kb
Download source code - 34 Kb


  • how to integrate win32 console program into a service

    Posted by Legacy on 10/24/2002 07:00am

    Originally posted by: ruilin yang

    Please help me. I am a relatively new c++/MFC programers. I created an ATL service module and compiled successfully. I also write a seperate win32 console program using ADO to do database manapulations, which works fine.

    I want to implement this win32 console program as window service (atl service or win console service) or integrate it to a Service program.

    I like my ATL Service (win service) program to call (or integrate) my Win32 console program. When I add my win32 console .cpp files to my ATL project I can not get compiled. There are certainly a lots conflicts. I do not need any displaying windows.

    Please give me some advance for the integration.

    thanks in advance.


  • Who's Stopped/Started Service

    Posted by Legacy on 10/04/2002 07:00am

    Originally posted by: Mark Potter

    Is it possible to get information on who has stopped or started a service?

  • How can i use it to get services of a remote machine

    Posted by Legacy on 12/18/2001 08:00am

    Originally posted by: Frank Richard


    I want to get a list of all the services running on a remote computer. How can i use it?

  • interact with desktop

    Posted by Legacy on 12/15/2001 08:00am

    Originally posted by: Shrishail Rana

    Dear Sir,

    I was very happy to read your article in codeguru about Windows NT service.
    But there is a question. How a service can interact with desktop and install
    icon in system tray.

    Here are the functions that are used to allow a service to interact with
    I got them from a service complied file. The Service shows an icon in the
    system tray. It uses following function in this order


    I think possibly using the handle from getdesktopwindow it install an icon
    in system tray. but i was not sucessful.

    I will be very grateful to you if anyone could guide me in this regard.

    With Kindest regards,

    Shrishail Rana

  • Set Account doesn't work

    Posted by Legacy on 05/02/2001 07:00am

    Originally posted by: Rudy Chung

    Dear Wheeler,

    When I use your tool to set service start name,
    it had an error message telling "Unable to Modified Mars".

    But when I use "service" in control pannel,
    this user account is OK.

    Do you know what's wrong?

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date