![]() |
General Reading »
Hardware & System »
Services
Intermediate
CNTService v1.06 - NT Service FrameworkBy PJ NaughterA class framework for developing NT services in MFC. |
VC6, MFC, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
CNTService, a collection of freeware MFC classes which provide a class framework
for developing NT services in MFC.
For detailed information about NT services, how to develop them and their relationship to other NT subsystems, I would suggest you thoroughly read the relevant documentation which comes with the Platform SDK.
| Features |
| Usage |
| History |
| Class Framework Reference |
| Planned Enhancements |
| References |
| Contacting the Author |
#include ntserv.h in which ever of your modules needs to make calls to the class and
derive your own service class from CNTService and override the necessary functions.
InitInstance() in the module
"app.cpp".
History
V1.0 (17 July 1998)
24 August 1998
V1.01 (17 May 1999)
CNTEventLogSource::Report() as reported by Marin Kunev.
V1.02 (5 September 1999)
V1.03 (3 October 1999)
GetProfileStringArray(),
WriteProfileStringArray(), GetProfileBinary() and
WriteProfileBinary() methods to the CNTService class.
V1.04 (5 October 1999)
V1.05 (10 October 1999)
V1.06 (24 January 2000)
#included into the final rc file testsrv.rc. This is done so that
the testsrc.rc file can be edited by the resource designer inside Visual C++. In
previous versions of CNTService, if your tried to edit the rc file (which
was generated by the MC command line compiler), you would end up corrupting the file.
If you are developing your own service using CNTService, then I would
suggest you take this approach. What you need to do is create a resource script inside
VC++, adding whatever resources you want to be in your services resources (e.g. version
info, strings etc), then bring up the resource includes dialog and modify the
Compile-Time directives to #include "ntserv_msg.rc" or your version of rc
file which was generated by MC by compiling your .mc file. You should also check out
the project settings in the demo service provided with CNTService to see
how it handles compilation of the .mc file via a batch file (right mouse click on
ntserv_msg.mc and select settings).
Class Framework Reference
The framework consists of the following classes:
CNTServiceCommandLineInfo
CNTEventLogSource
CNTService
CNTScmService
CNTServiceControlManager
CEventLogRecord
CNTEventLog
The CNTServiceCommandLineInfo class aids in parsing the command line at application
startup. It is based almost exactly upon the way that the CCommandLineInfo class in
MFC works.
A service application will typically create a local instance of this class in your main/wmain or
InitInstance() function. This object is then passed to
CNTService::ParseCommandLine(), which fills the CNTServiceCommandLineInfo
object. The CNTServiceCommandLineInfo object is then passed to
CNTService::ProcessShellCommand() to handle the command-line arguments and flags.
You can use this object to encapsulate the following command-line options and parameters:
| Command-line argument | Command executed |
| app /install | Installs the service. |
| app /remove | /uninstall | Uninstalls the service. |
| app /help | Calls the virtual CNTService::OnHelp() function. |
Derive a new class from CCommandLineInfo to handle other flags and parameter values.
CNTEventLogSource provides a wrapper class for writing events to the NT event log. You
could consider this as the server side to the Event log APIs.
Functions this class provides include:
CNTEventLogSource
~CNTEventLogSource
operator HANDLE
Attach
Detach
Register
Report
Deregister
Install
Uninstall
Remarks:
This is the default constructor which just initialises all internal variables to a safe state.
See Also:
~CNTEventLogSource
Remarks:
This is the standard destructor for the class. Internally it will call
Deregister to ensure that any handle that is opened by this instance
is closed.
See Also:
CNTEventLogSource, Deregister
Return Value:
The underlying SDK handle representing this event log source.
Remarks:
This function exposes the underlying handle which the CNTEventLogSource class wraps.
This function is provided for integration with legacy code which uses the handle directly.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
::RegisterEventSource().
Remarks:
Use this member function to attach an existing SDK handle to a CNTEventLogSource.
See Also:
Detach
Return Value:
The SDK event log source handle.
Remarks:
Call this function to detach m_hEventLogSource from the CNTEventLogSource object and
set m_hEventLogSource to NULL.
See Also:
Attach
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
HKEY_LOCAL_MACHINE
System
CurrentControlSet
Services
EventLog
Application
WinApp
Security
System
Remarks:
Use this function to register a source of logging into the event log. Internally the
CNTService class contains a member variable (m_EventLogSource) of type
CNTEventLogSource which calls this function in its construction.
See Also:
Deregister
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
| Value | Meaning |
|---|---|
| EVENTLOG_ERROR_TYPE | Error event |
| EVENTLOG_WARNING_TYPE | Warning event |
| EVENTLOG_INFORMATION_TYPE | Information event |
| EVENTLOG_AUDIT_SUCCESS | Success Audit event |
| EVENTLOG_AUDIT_FAILURE | Failure Audit event |
Remarks:
These 4 versions of Report report a message to the event log. The 4 versions are provided to allow
the programmer to use the one most suitable for the particular situation at hand.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Remarks:
Call this function to close the handle to the event log. This function will be called in the
destructor in case you forget to close the handle yourself.
See Also:
Register
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Call this function to setup the necessary entries in the registry so that the Event Viewer can
correctly locate the message file for messages displayed in the event log. This function is
called as part of CNTService::Install() using appropriate values.
See Also:
Uninstall
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Remarks:
Call this function to remove the entries from the registry which were setup by the method
Install().
See Also:
Install
CNTService is the class which provides a C++ framework upon which you can develop your own
MFC C++ based services. The class makes heavy use of virtual functions which your service class should
override.
Functions this class provides include:
CNTService
~CNTService
WriteProfileString
WriteProfileInt
WriteProfileBinary
WriteProfileStringArray
GetProfileString
GetProfileInt
GetProfileBinary
GetProfileStringArray
ParseCommandLine
ProcessShellCommand
ReportStatustoSCM
RegisterCtrlHandler
ServiceCtrlHandler
ServiceMain
OnStop
OnPause
OnContinue
OnInterrogate
OnShutdown
OnUserDefinedRequest
Run
Install
Uninstall
Debug
ShowHelp
Parameters:
| Value | Meaning |
|---|---|
| SERVICE_ACCEPT_STOP | The service can be stopped. This enables the SERVICE_CONTROL_STOP value. |
| SERVICE_ACCEPT_PAUSE_CONTINUE | The service can be paused and continued. This enables the SERVICE_CONTROL_PAUSE and SERVICE_CONTROL_CONTINUE values. |
| SERVICE_ACCEPT_SHUTDOWN | The service is notified when system shutdown occurs. This enables the system to send a SERVICE_CONTROL_SHUTDOWN value to the service. The ControlService function cannot send this control code. |
Remarks:
This is the standard constructor which initializes a number of internal variables based on the
parameters sent in.
See Also:
~CNTService
Remarks:
Standard destructor for the class.
See Also:
CNTService
Return Value:
TRUE if successful; otherwise FALSE.
Parameters:
Remarks:
Call this member function to write the specified string into the registry where Services are meant
to store their configuration setting i.e.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ServiceName\Parameters.
Return Value:
TRUE if successful; otherwise FALSE.
Parameters:
Remarks:
Call this member function to write the specified value into the registry where Services are meant
to store their configuration setting i.e.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ServiceName\Parameters.
Return Value:
TRUE if successful; otherwise FALSE.
Parameters:
Remarks:
Call this member function to write the specified binart data into the registry where Services are
meant to store their configuration setting i.e.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ServiceName\Parameters.
Return Value:
The return value is the string from the registry or lpszDefault if the string cannot be
found. The maximum string length supported by the framework is _MAX_PATH. If
lpszDefault is NULL, the return value is an empty string.
Parameters:
Remarks:
Call this member function to retrieve the string associated with an entry within the specified
section in the registry.
Return Value:
The integer value of the string that follows the specified entry if the function is successful.
The return value is the value of the nDefault parameter if the function does not find the
entry. The return value is 0 if the value that corresponds to the specified entry is not an
integer.
Parameters:
Remarks:
Call this member function to retrieve the value of an integer from an entry within a specified
section in the registry.
This member function is not case sensitive, so the strings in the lpszSection and lpszEntry parameters may differ in case.
Return Value:
TRUE if successful; otherwise FALSE.
Parameters:
Remarks:
Call this member function to set a binary value associated with an entry within the specified
section in the registry. Internally the data is stored in the registry as a REG_BINARY value.
Note that the caller of the function is responsible for freeing the memory associated with the
data in ppData. This can be achieved using: delete [] *ppData.
Return Value:
TRUE if successful; otherwise FALSE.
Parameters:
Remarks:
Call this member function to retrieve a string array associated with an entry within the specified
section in the registry. The value is stored as a MULTI_SZ string in the registry.
Parameters:
Remarks:
Call this member function to parse the command line and send the parameters, one at a time, to
CNTServiceCommandLineInfo::ParseParam().
Return Value:
TRUE if the shell command is processed successfully otherwise FALSE.
Parameters:
Remarks:
This member function is called by your InitInstance(), main or wmain to accept the
parameters passed from the CNTServiceCommandLineInfo object identified by
rCmdInfo, and perform the indicated action.
The data members of the CNTServiceCommandLineInfo object, identified by
CNTServiceCommandLineInfo::m_nShellCommand, are of the following enumerated type, which
is defined within the CNTServiceCommandLineInfo class.
enum {
RunAsService,
InstallService,
UninstallService,
DebugService,
ShowServiceHelp,
};
Return Value:
TRUE if the SCM was notified successfully of this services state otherwise FALSE. To get extended
error information, call GetLastError().
Parameters:
| Value | Meaning |
| SERVICE_STOPPED | The service is not running. |
| SERVICE_START_PENDING | The service is starting. |
| SERVICE_STOP_PENDING | The service is stopping. |
| SERVICE_RUNNING | The service is running. |
| SERVICE_CONTINUE_PENDING | The service continue is pending. |
| SERVICE_PAUSE_PENDING | The service pause is pending. |
| SERVICE_PAUSED | The service is paused. |
SetServiceStatus() function with either an incremented
dwCheckPoint value or a change in dwCurrentState. If the amount of time
specified by dwWaitHint passes, and dwCheckPoint has not been incremented, or
dwCurrentState has not changed, the service control manager or service control
program can assume that an error has occurred.
Remarks:
These two functions report the current state of the service back to the service control manager.
The first versions uses the parameters specified and as well as updated the services own internal
state will report it to the SCM. The second version uses the existing state of the service when
reporting to the SCM.
Return Value:
TRUE if the Control handler for this service was successfully registered otherwise FALSE. To get
extended error information, call GetLastError().
Remarks:
You would call this at the beginning of your derived classes ServiceMain to report to the SCM which
function to callback on when making requests to the service. Internally when a request is made it
will be routed to the appropriate virtual function.
See Also:
ServiceCtrlHandler
Return Value:
TRUE if successful; otherwise FALSE.
Parameters:
| Value | Meaning |
| SERVICE_CONTROL_STOP | Requests the service to stop. |
| SERVICE_CONTROL_PAUSE | Requests the service to pause. |
| SERVICE_CONTROL_CONTINUE | Requests the paused service to resume. |
| SERVICE_CONTROL_INTERROGATE | Requests the service to update immediately its current status information to the service control manager. |
| SERVICE_CONTROL_SHUTDOWN | Requests the service to perform cleanup tasks, because the system is shutting down. |
This value can also be a user-defined control code, as described in the following table:
| Value | Meaning |
| Range 128 to 255. | The service defines the action associated with the control code. The hService handle must have SERVICE_USER_DEFINED_CONTROL access. |
Remarks:
This function is called into by the SCM and internally it delegates to the appropriate virtual
function. For example if a SERVICE_CONTROL_STOP request arrives then this function will
call the virtual OnStop() function. This function will not normally have to be
overridden in your derived class. Please bear in mind that this function will be called in the
context on the main thread on your service and not the thread in which your service does it main
work (its ServiceMain() handler).
Return Value:
TRUE if successful; otherwise FALSE.
Parameters:
Remarks:
In your derived class you are responsible for writing your own ServiceMain() function
for your service.
When a service control program requests that a new service run, the SCM starts the service and
sends a start request to the control dispatcher. The control dispatcher creates a new thread to
execute the ServiceMain() function for the service.
The ServiceMain() function should perform the following tasks:
ServiceMain().
SetServiceStatus(), specifying the
SERVICE_RUNNING state in the SERVICE_STATUS structure.
SERVICE_STATUS structure. Be sure
to set the dwServiceSpecificExitCode and dwWin32ExitCode members of the
SERVICE_STATUS structure to identify the error.
Remarks:
This function will be called whenever a SERVICE_CONTROL_STOP request comes in from the SCM. Your
derived class should do whatever is necessary to cause your service to stop.
Remarks:
This function will be called whenever a SERVICE_CONTROL_PAUSE request comes in from the SCM. Your
derived class should do whatever is necessary to cause your service to pause.
Remarks:
This function will be called whenever a SERVICE_CONTROL_CONTINUE request comes in from the SCM.
Your derived class should do whatever is necessary to cause your service to continue.
Remarks:
This function will be called whenever a SERVICE_CONTROL_INTERROGATE request comes in from the SCM.
The default implementation just calls ReportStatusToSCM to inform
the SCM.
Remarks:
This function will be called whenever a SERVICE_CONTROL_SHUTDOWN comes in from the SCM. Your
derived class should do whatever is necessary to cause your service to shutdown.
Remarks:
This function will be called whenever a user defined request comes in from the SCM. Your derived
class should do whatever is appropriate for its service. In the example service provided, it
simply changes the frequency of beeps emitted by the service.
Remarks:
Calling this function will cause a service to start running. Internally it will set up an
appropriate SERVICE_TABLE_ENTRY array and call StartServiceCtrlDispatcher to kick of the service.
You would normally call this in your main, wmain or InitInstance. If you are using the
CNTServiceCommandLineInfo class and
ParseCommandLine() and
ProcessShellCommand() member functions of CNTService
then there is no need to call this function.
Remarks:
This will install a service. Internally it will call into the SCM API to set this service up as an
on demand service with no dependencies. In future versions of CNTService, virtual
functions will be provided to allow more customisation in this area. It will also install the
service so that it can report events to the event log as well as letting Event Viewer filter using
the friendly name of the service. This function will be called internally by the
CNTServiceCommandLineInfo if "-install" is specified on
the command line.
Remarks:
The is the corollary function of Install and will remove the service from the SCM database and
remove it event log registry entries. Please bear in mind that once this is done, event viewer
will no longer be able to correctly display any messages the service generated while it was
installed. the CNTServiceCommandLineInfo if "-uninstall"
or "-remove" is specified on the command line.
Remarks:
This will run a service without interacting with the SCM, in effect a "debug" mode. This helps
when testing your application as it will stop the SCM from timing out your service as it is being
debugged. Internally this function will just call the ServiceMain function of your class. Remember
that in this case your service code will be running in the same thread as the main thread so it
may mask problems which only arise when the code is executed as a real service. This function will
be called internally by CNTServiceCommandLineInfo if
"-debug" is specified on the command line.
Remarks:
This function will be called internally by
CNTServiceCommandLineInfo if "-help" or "-?" is specified
on the command line. It is up to you to either print some message to the console if you are
developing a console mode service or display some helpful window if its a GUI app. The sample
service simply displays a message using AfxMessageBox() as it was developed using the
GUI subsystem.
CNTScmService is a class which encapsulates a service as returned from the Service Control Manager, in effect a SC_HANDLE. An instance of a CNTScmService is usually acquired by a call to CNTServiceControlManager::Open. Once retrieved the class allows you to control the service, change its configuration and query a service's state.
Functions this class provides include:
CNTScmService
~CNTScmService
Close
operator SC_HANDLE
Attach
Detach
ChangeConfig
Control
Stop
Pause
Continue
Interrogate
Start
AcceptStop
AcceptPauseContinue
AcceptShutdown
QueryStatus
QueryConfig
Create
Delete
EnumDependents
QueryObjectSecurity
SetObjectSecurity
Remarks:
This is the default constructor which just initialises all internal variables to a safe state.
See Also:
~CNTScmService()
Remarks:
This is the standard destructor for the class. Internally it will call
Close() to ensure that any handle that is opened by this instance is
closed.
See Also:
CNTScmService(), Close().
Remarks:
This frees the SC_HANDLE by internally calling CloseServiceHandle which this class encapsulates.
Return Value:
The underlying SDK service handle representing this class.
Remarks:
This function exposes the underlying handle which the CNTScmService class wraps. This function is
provided for integration with legacy code which uses the handle directly.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Use this member function to attach an existing SDK handle to a CNTScmService.
See Also:
Detach.
Return Value:
The SDK service handle.
Remarks:
Call this function to detach m_hService from the CNTScmService object and set m_hService
to NULL.
See Also:
Attach.
Remarks:
This is a simple wrapper for the SDK call ChangeServiceConfig(). See the SDK for full
details on this function.
Parameters:
| Value | Meaning |
| SERVICE_CONTROL_STOP | Requests the service to stop. |
| SERVICE_CONTROL_PAUSE | Requests the service to pause. |
| SERVICE_CONTROL_CONTINUE | Requests the paused service to resume. |
| SERVICE_CONTROL_INTERROGATE | Requests the service to update immediately its current status information to the service control manager. |
| SERVICE_CONTROL_SHUTDOWN | Requests the service to perform cleanup tasks, because the system is shutting down. |
This value can also be a user-defined control code, as described in the following table:
| Value | Meaning |
| Range 128 to 255. | The service defines the action associated with the control code. The hService handle must have SERVICE_USER_DEFINED_CONTROL access. |
Remarks:
This is a simple wrapper for the SDK call ControlService() SDK Call.
Remarks:
This is a simple wrapper for calling Control() with the parameter
SERVICE_CONTROL_STOP.
Remarks:
This is a simple wrapper for calling Control() with the parameter
SERVICE_CONTROL_PAUSE.
Remarks:
This is a simple wrapper for calling Control() with the parameter
SERVICE_CONTROL_CONTINUE.
Remarks:
This is a simple wrapper for calling Control() with the parameter
SERVICE_CONTROL_INTERROGATE.
Return Value:
TRUE If the function succeeds otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Starts this service with the specified parameters.
Return Value:
TRUE If the function succeeds otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Queries this service to determine if this service can currently be stopped.
Return Value:
TRUE If the function succeeds otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Queries this service to determine if this service can currently be paused / continued.
Return Value:
TRUE If the function succeeds otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Queries this service to determine if this service handles the shutdown request.
Return Value:
TRUE If the function succeeds otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Queries this service for its current status.
Return Value:
TRUE If the function succeeds otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Queries this service for its current configuration. Bear in mind that since the QUERY_SERVICE_CONFIG
is a variable sized structure, internally this function will allocate the required memory for
lpServiceConfig, it is the responsibility of the client to delete this structure. This can
be done as follows:
LPQUERY_SERVICE_CONFIG lpConfig = NULL; service.QueryConfig(lpConfig); delete [] (BYTE*) lpConfig;
Remarks:
This is a simple wrapper for the SDK call CreateService(). See the SDK for full
details on this function.
Remarks:
This is a simple wrapper for the SDK call DeleteService(). See the SDK for full
details on this function.
Parameters:
| Value | Meaning |
| SERVICE_ACTIVE | Enumerates services that are in the following states: SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_RUNNING, SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING, and SERVICE_PAUSED. |
| SERVICE_INACTIVE | Enumerates services that are in the SERVICE_STOPPED state. |
| SERVICE_STATE_ALL | Combines the following states: SERVICE_ACTIVE and SERVICE_INACTIVE. |
Remarks:
This function allows you to enumerate the services upon which this service is dependent. Internally
this calls EnumDependentServices() and calls the callback function for each service.
The format of the callback function is:
BOOL CALLBACK ENUM_SERVICES_PROC(DWORD dwData, ENUM_SERVICE_STATUS& ServiceStatus);
Return TRUE from the function to continue enumeration and FALSE to stop enumeration.
Remarks:
This is a simple wrapper for the SDK call QueryServiceObjectSecurity(). See the SDK
for full details on this function.
Remarks:
This is a simple wrapper for the SDK call SetServiceObjectSecurity(). See the SDK for
full details on this function. Bear in mind that since the PSECURITY_DESCRIPTOR is a variable sized
structure, internally this function will allocate the required memory for lpSecurityDescriptor,
it is the responsibility of the client to delete this structure. This can be done as follows:
PSECURITY_DESCRIPTOR lpDescriptor = NULL; service.QueryObjectSecurity(whatever, lpDescriptor); delete [] (BYTE*) lpDescriptor;
CNTServiceControlManager is a class which encapsulates a connection to a Service Control
Manager (SCM) on some machine. Functionality provided includes enumeration, database locking and service
access.
Functions this class provides include:
CNTServiceControlManager
~CNTServiceControlManager
operator HANDLE
Attach
Detach
Open
Close
QueryLockStatus
EnumServices
OpenService
Lock
Unlock
Remarks:
This is the default constructor which just initialises all internal variables to a safe state.
See Also:
~CNTServiceControlManager().
Remarks:
This is the standard destructor for the class. Internally it will call
Close() to ensure that any handle that is opened by this instance is
closed.
See Also:
CNTServiceControlManager(), Close().
Return Value:
The underlying SDK service handle representing this class.
Remarks:
This function exposes the underlying handle which the CNTServiceControlManager class
wraps. This function is provided for integration with legacy code which uses the handle directly.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Use this member function to attach an existing SDK handle to a
CNTServiceControlManager.
See Also:
Detach
Return Value:
The SDK service control manager handle.
Remarks:
Call this function to detach m_hSCM from the CNTServiceControlManager object
and set m_hSCM to NULL.
See Also:
Attach
Remarks:
This is a simple wrapper for the SDK call OpenSCManager(). See the SDK for full
details on this function.
Remarks:
This frees the SC_HANDLE by internally calling CloseServiceHandle() which this class
encapsulates.
Remarks:
This frees the SC_HANDLE by internally calling CloseServiceHandle() which this class
encapsulates.
Remarks:
This is a simple wrapper for the SDK call QueryServiceLockStatus(). See the SDK for
full details on this function. Bear in mind that since the LPQUERY_SERVICE_LOCK_STATUS is a variable
sized structure, internally this function will allocate the required memory for lpLockStatus,
it is the responsibility of the client to delete this structure. This can be done as follows:
LPQUERY_SERVICE_LOCK_STATUS lpLockStatus = NULL; scm.QueryLockStatus(lpLockStatus); delete [] (BYTE*) lpLockStatus;
Parameters:
| Value | Meaning |
| SERVICE_WIN32 | Enumerates services of type SERVICE_WIN32_OWN_PROCESS and SERVICE_WIN32_SHARE_PROCESS. |
| SERVICE_DRIVER | Enumerates services of type SERVICE_KERNEL_DRIVER and SERVICE_FILE_SYSTEM_DRIVER. |
| Value | Meaning |
| SERVICE_ACTIVE | Enumerates services that are in the following states: SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_RUNNING, SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING, and SERVICE_PAUSED. |
| SERVICE_INACTIVE | Enumerates services that are in the SERVICE_STOPPED state. |
| SERVICE_STATE_ALL | Combines the following states: SERVICE_ACTIVE and SERVICE_INACTIVE. |
Remarks:
This function allows you to enumerate the services which in the SCM. Internally this calls
EnumServicesStatus() and calls the callback function for each service. The format of
the callback function is:
typedef BOOL CALLBACK ENUM_SERVICES_PROC(DWORD dwData, ENUM_SERVICE_STATUS& ServiceStatus);
Return TRUE from the function to continue enumeration and FALSE to stop enumeration.
Remarks:
This is a simple wrapper for the SDK call of the same name. See the SDK for full details on this
function.
Remarks:
This is a simple wrapper for the SDK call LockServiceDatabase(). See the SDK for full
details on this function.
Remarks:
This is a simple wrapper for the SDK call UnlockServiceDatabase(). See the SDK for full
details on this function.
CEventLogRecord is a C++ wrapper class for the EVENTLOGRECORD structure as provided in the SDK.
For anyone who has had to use this class using raw SDK calls, you will appreciate the easier access which the
class provides.
Functions and members this class provides include:
CEventLogRecord
operator=
m_dwRecordNumber
m_TimeGenerated
m_TimeWritten
m_dwEventID
m_wEventTypes
m_wEventCategory
m_UserSID
m_Strings
m_Data
m_sSourceName
m_sComputerName
Parameters:
Remarks:
The standard copy constructor.
Remarks:
Contains the record number for this event log entry.
Remarks:
The CTime representation of when this entry was submitted.
Remarks:
The CTime representation of when this entry was written to the event log.
Remarks:
Specifies the event. This is specific to the source that generated the event log entry, and is used,
together with SourceName, to identify a message in a message file that is presented to the
user while viewing the log.
Remarks:
Specifies the type of event. This member can be one of the following values:
| Value | Meaning |
| EVENTLOG_ERROR_TYPE | Error event |
| EVENTLOG_WARNING_TYPE | Warning event |
| EVENTLOG_INFORMATION_TYPE | Information event |
| EVENTLOG_AUDIT_SUCCESS | Success Audit event |
| EVENTLOG_AUDIT_FAILURE | Failure Audit event |
Remarks:
A CByteArray representation of the security identifier of the active user at the time this event was
logged.
Remarks:
A CStringArray representation of the strings which are merged into the message before it is
displayed to the user.
Remarks:
A CByteArray representation of the event-specific information within this event record.
Remarks:
Contains the string specifying the name of the source (application, service, driver, subsystem) that
generated the entry.
Remarks:
Contains the string specifying the name of the computer that generated this event.
CNTEventLog is a C++ wrapper class for accessing the NT Event Logs. You can consider this as
the client side to the Event Log APIs.
Functions this class provides include:
CNTEventLog
~CNTEventLog
operator HANDLE
Attach
Detach
Open
OpenBackup
OpenApplication
OpenSystem
OpenSecurity
Close
Backup
Clear
GetNumberOfRecords
GetOldestRecord
NotifyChange
ReadNext
ReadPrev
Remarks:
This is the default constructor which just initialises all internal variables to a safe state.
See Also:
~CNTEventLog().
Remarks:
This is the standard destructor for the class. Internally it will call Close()
to ensure that any handle that is opened by this instance is closed.
See Also:
CNTEventLog(), Close().
Return Value:
The underlying SDK event log handle representing this class.
Remarks:
This function exposes the underlying handle which CNTEventLog class wraps. This function
is provided for integration with legacy code which uses the handle directly.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Use this member function to attach an existing SDK handle to a CNTEventLog.
See Also:
Detach
Return Value:
The SDK event log handle.
Remarks:
Call this function to detach m_hEventLog from the CNTEventLog object and set
m_hEventLog to NULL.
See Also:
Attach
Remarks:
This is a simple wrapper for the SDK call OpenEventLog(). See the SDK for full details
on this function.
Remarks:
This is a simple wrapper for the SDK call OpenBackupEventLog(). See the SDK for full
details on this function.
Remarks:
This is a sample wrapper for opening the "Application" event log on the specified computer, internally
it just calls Open() with the appropriate string "Application".
Remarks:
This is a sample wrapper for opening the "system" event log on the specified computer, internally it
just calls Open() with the appropriate string "System".
Remarks:
This is a sample wrapper for opening the "Security" event log on the specified computer, internally it
just calls Open() with the appropriate string "Security".
Remarks:
This frees the HANDLE by internally calling CloseEventLog which this class encapsulates.
Remarks:
This is a simple wrapper for the SDK call BackupeventLog(). See the SDK for full details
on this function.
Remarks:
This is a simple wrapper for the SDK call ClearEventLog(). See the SDK for full details
on this function.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
This is a simple wrapper for the SDK call GetNumberOfEventLogRecords(). See the SDK for
full details on this function.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
This is a simple wrapper for the SDK call GetOldestEventLogRecord(). See the SDK for
full details on this function.
Remarks:
This is a simple wrapper for the SDK call NotifyChangeEventLog(). See the SDK for full
details on this function.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Reads the next record in forward chronological order from the event log. When this function returns
successfully, the read position is incremented by one ready for the next read to occur.
Return Value:
TRUE if the function was successful, otherwise FALSE. To get extended error information, call
GetLastError().
Parameters:
Remarks:
Reads the next record in reverse chronological order from the event log. When this function returns
successfully, the read position is decremented by one ready for the next read to occur.
Contacting the Author
PJ Naughter
Email: pjn@indigo.ie
Web: http://www.naughter.com
24 January 2000
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 3 Mar 2000 Editor: Valerie Bradley |
Copyright 2000 by PJ Naughter Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |