in category
Search All
Tutorials
.Net
ASP
C/C++
ColdFusion
Delphi
DHTML
HTML
Java
Javascript
Perl
PHP
VBScript
Visual Basic
XML
Visual Basic
/
NT Samples
/ Event Log in NT
Snippet details
ID:
411
Viewed:
1277
Added:
2002-08-19
Version:
User Rated at:
Rate This:
Select a rating...
5 .. Best
4
3 .. Average
2
1 .. Worst
Snippets in this catagory
Show Printable Version
Event Log in NT
General Details
Snippet uploaded by:
snippet
Email :
webmaster@snippetlibrary.com
Snippet By:
Unknown
Snippet By:
Unknown
Declarations
Highlight All
Option Explicit Declare Function RegisterEventSource Lib "advapi32.dll" Alias _ "RegisterEventSourceA" (ByVal lpUNCServerName As String, _ ByVal lpSourceName As String) As Long Declare Function DeregisterEventSource Lib "advapi32.dll" ( _ ByVal hEventLog As Long) As Long 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 Declare Function GetLastError Lib "kernel32" () As Long Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _ hpvDest As Any, hpvSource As Any, _ ByVal cbCopy As Long) Declare Function GlobalAlloc Lib "kernel32" ( _ ByVal wFlags As Long, _ ByVal dwBytes As Long) As Long 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
Code
Highlight All
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 Sub Main() 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
No Reviews to show
Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.
Subject:
Reviewed By:
Write a review:
Terms of Conditions
Powered By
© 2005
snippetlibrary.com
All Rights Reserved.