NT Event Viewer Loggin with API Calls

Category:
System/API
Type:
Modules
Difficulty:
Intermediate
Author:
John Conwell

Version Compatibility: Visual Basic 6

More information:
I've posted this functionality here before, but it needed a supporting exe. This way of writing to the Event Viewer is done with API calls and no supporting files are needed. Just add the code to a module or class module. Call the LogErrorToEventViewer method, passing in the message and the severity level and it will write to the Event Viewer on the NT box that your currently using. With a little modification you can add binary data to your posted event, Populate the User field in the message and you can write to a different NT machine's Event Viewer. Just do some research on the api calls to figure those out.

I've written this because VB's LogEvent method is really no good. It works only part of the time and under the Source header in the Event Viewer it writes VBRuntime. So if you have 5 apps writing to the Event Viewer, all 5 have VBRuntime at the source. Not very helpful. This way you can easily see what apps have errors.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: