могу предложить следующий код. К недостаткам можно отнести что при вставке сообщения в EventLog будут присутсвовать слова "В источнике не найдено описание кода...." Это тоже говорят можно исправить но я не смог слинковать библиотеку Option Explicit Public Const EVENTLOG_SUCCESS = 0 Public Const EVENTLOG_ERROR_TYPE = 1 Public Const EVENTLOG_WARNING_TYPE = 2 Public Const EVENTLOG_INFORMATION_TYPE = 4 Public Const EVENTLOG_AUDIT_SUCCESS = 8 Public Const EVENTLOG_AUDIT_FAILURE = 10 Public Declare Function RegisterEventSource Lib "Advapi32.dll" Alias _ "RegisterEventSourceA" _ (ByVal lpUNCServerName As String, _ ByVal lpSourceName As String) As Long ' The RegisterEventSource function returns a handle that ' can be used with the ReportEvent function to log an event. ' Any source name can be used; ' it will be carried in the event log record so that Event Viewer can use it for filtering. ' HANDLE RegisterEventSource( ' LPCTSTR lpUNCServerName, // server name for source ' LPCTSTR lpSourceName // source name for registered handle ' ); ' Parameters ' lpUNCServerName ' Points to a null-terminated string that specifies the Universal Naming Convention (UNC) ' name of the server on which this operation is to be performed. ' If this parameter is NULL, the operation is performed on the local computer. ' lpSourceName ' Points to a null-terminated string that specifies the name of the source referenced ' by the returned handle. The source name must be a subkey of a logfile entry ' under the EventLog key in the registry. ' For example, the source name WinApp would be valid if the registry had the following form: ' HKEY_LOCAL_MACHINE ' System ' CurrentControlSet ' Services ' EventLog ' Application ' WinApp ' Security ' System ' If the source name cannot be found, the event logging service uses the ' Application logfile with no message files for the event identifier or category. ' ' Return Values ' If the function succeeds, the return value is a handle that can be used with the ReportEvent function. ' If the function fails, the return value is NULL. To get extended error information, call GetLastError. Public Declare Function DeregisterEventSource Lib "Advapi32.dll" (ByVal hEventLog As Long) As Long ' The DeregisterEventSource function closes a handle returned by the RegisterEventSource function. ' BOOL DeregisterEventSource( ' HANDLE hEventLog // handle to event log ' ); ' Parameters ' hEventLog ' Identifies the event log whose handle was returned by RegisterEventSource. ' Return Values ' If the function succeeds, the return value is nonzero. ' If the function fails, the return value is zero. To get extended error information, call GetLastError. Public Declare Function ReportEvent Lib "Advapi32.dll" Alias _ "ReportEventA" _ (ByVal hEventLog As Long, _ ByVal wType As Integer, _ ByVal wCategory As Integer, _ ByVal dwEventID As Long, _ ByVal lpUserSid As Any, _ ByVal wNumStrings As Integer, _ ByVal dwDataSize As Long, _ plpStrings As Long, _ lpRawData As Any) As Boolean ' The ReportEvent function writes an entry at the end of the specified event log. ' BOOL ReportEvent( ' HANDLE hEventLog, // handle returned by RegisterEventSource ' WORD wType, // event type to log ' WORD wCategory, // event category ' DWORD dwEventID, // event identifier ' PSID lpUserSid, // user security identifier (optional) ' WORD wNumStrings, // number of strings to merge with message ' DWORD dwDataSize, // size of binary data, in bytes ' LPCTSTR *lpStrings, // array of strings to merge with message ' LPVOID lpRawData // address of binary data ' ); 'Parameters 'hEventLog ' Identifies the event log. This handle is returned by the RegisterEventSource function. 'wType ' Specifies the type of event being logged. This parameter 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 ' ' wCategory ' Specifies the event category. This is source-specific information; the category can have any value. 'dwEventID ' Specifies the event identifier. ' The event identifier specifies the message that goes with this event as an entry in ' the message file associated with the event source. 'lpUserSid ' Points to the current user's security identifier. ' This parameter can be NULL if the security identifier is not required. 'wNumStrings ' Specifies the number of strings in the array pointed to by the lpStrings parameter. ' A value of zero indicates that no strings are present. 'dwDataSize ' Specifies the number of bytes of event-specific raw (binary) data to write to the log. ' If this parameter is zero, no event-specific data is present. 'lpStrings ' Points to a buffer containing an array of null-terminated strings that are merged into ' the message before Event Viewer displays the string to the user. ' This parameter must be a valid pointer (or NULL), even if wNumStrings is zero. 'lpRawData ' Points to the buffer containing the binary data. ' This parameter must be a valid pointer (or NULL), even if the dwDataSize parameter is zero. ' Return Valu
Ответить
|