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

More by Author

Must Read