Write to NT's Event Log 
Author Message
 Write to NT's Event Log

With this code I can write to the Event Log

'******Module1.bas******
Option Explicit
Public Declare Function RegisterEventSource Lib "advapi32.dll" Alias
"RegisterEventSourceA" (ByVal lpUNCServerName As String, ByVal lpSourceName
As String) As Long
Public Declare Function DeregisterEventSource Lib "advapi32.dll" (ByVal
hEventLog As Long) As Long
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
Public Declare Function GetLastError Lib "kernel32" () As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest
As Any, hpvSource As Any, ByVal cbCopy As Long)
Public Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long,
ByVal dwBytes As Long) As Long
Public Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As
Long
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 Sub LogNTEvent(sString As String, iLogType As Integer, iEventID As
Long)
Dim bRC As Boolean
Dim iNumStrings As Integer
Dim hEventLog As Long
Dim hMsgs As Long
Dim cbStringSize As Long

    hEventLog = RegisterEventSource("", App.Title)
    cbStringSize = Len(sString) + 1
    hMsgs = GlobalAlloc(&H40, cbStringSize)
    CopyMemory ByVal hMsgs, ByVal sString, cbStringSize
    iNumStrings = 1
    If ReportEvent(hEventLog, iLogType, 0, iEventID, 0&, iNumStrings,
cbStringSize, hMsgs, hMsgs) = 0 Then
        MsgBox GetLastError()
    End If
    Call GlobalFree(hMsgs)
    DeregisterEventSource (hEventLog)
End Sub

'***********Form1*********
Private Sub Command1_Click()
    Call LogNTEvent("Information from " & App.EXEName,
EVENTLOG_INFORMATION_TYPE, 1001)
    Call LogNTEvent("Warning from " & App.EXEName, EVENTLOG_WARNING_TYPE,
1002)
    Call LogNTEvent("Error from " & App.EXEName, EVENTLOG_ERROR_TYPE, 1003)
    MsgBox "Done"
End Sub

but the binary data appears like this

0000: 58 74 1a 00 b0 ad 19 00   Xt..-..
0008: 01 00 00 00 c0 f5 12 00   ....?..
0010: 3a c3 18 00 04 00 00 00   :?......
0018: 1a 00                     ..

How can i log it correctly.



Mon, 04 Jun 2001 03:00:00 GMT  
 Write to NT's Event Log
goto www,netfokus.dk/vbadmincode .  There is an example that covers
everything to do with the event log.

John Timney (MVP)

Quote:

>How can i log it correctly.



Mon, 04 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Event Log: Writing to the NT Event Log

2. Does anyone know how to write an event into NT Event Log

3. Writing events to the NT Event Log

4. Making an Event Log Message File in VB (NOT WRITING TO THE EVENT LOG)

5. Logging events to NT Event Log from VB5

6. Write to NT event log

7. Writing to the Windows NT Event Log - Example please

8. Write NT Event Log in VB 5

9. Writing to NT Event Logs

10. Write errors at Windows Nt Event Log

11. Write error at Windows NT Event Log

12. Writing to the NT Event Log

 

 
Powered by phpBB® Forum Software