CSysService

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
      Constructor
      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.

Features:

  • 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.

Credits

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.

Downloads

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


Comments

  • how to integrate win32 console program into a service

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

    Originally posted by: ruilin yang

    Guru's,
    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.

    Ruilin

    Reply
  • Who's Stopped/Started Service

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

    Originally posted by: Mark Potter

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

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

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

    Originally posted by: Frank Richard

    Hi,

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

    Reply
  • interact with desktop

    Posted by Legacy on 12/15/2001 12: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
    desktop.
    I got them from a service complied file. The Service shows an icon in the
    system tray. It uses following function in this order

    getprocesswindowstation
    openwindowstation
    setprocesswindowstation
    opendesktop
    setthreaddesktop
    getdesktopwindow

    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

    Reply
  • Set Account doesn't work

    Posted by Legacy on 05/02/2001 12: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?

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Relying on outside companies to manage your network and server environments for your business and applications to meet the needs and demands of your users can be stressful. This is especially true as many Managed Hosting organizations fail to meet their service level agreements. Read this Forrester total economic impact report and learn what makes INetU different and how they exceed their customers' managed hosting expectations.

Most Popular Programming Stories

More for Developers

RSS Feeds