Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: custom event logs read event log
EvtTest
Message Compiler
"C:\Program Files\Microsoft Visual Studio\VC98\Bin\mc.exe"
EvtTestMsg.mc
.mc
extension!)#include "<filename>.rc"
<filename>
is the name of the Message
File, e.g., EvtTestMsg
C:\Program Files\Microsoft Visual Studio\My
Projects\<projectname>\Debug
<projname>
is the name of the project,
e.g., EvtTest
Sample code:
; set base key path rootKey = "SYSTEM\CurrentControlSet\Services\Eventlog\Application\EvtTest" ; create/open key handle key = RegCreateKey ( @REGMACHINE, rootKey ) ; set CategoryCount DWORD value RegSetEx ( key, "[CategoryCount]", "1", "", "4" ) ; set CategoryMessageFile EXPAND_SZ value RegSetEx ( key, "[CategoryMessageFile]", "c:\temp\evttest.exe", "", "2" ) ; set EventMessageFile EXPAND_SZ value RegSetEx ( key, "[EventMessageFile]", "c:\temp\evttest.exe", "", "2" ) ; set TypeSupported DWORD value RegSetEx ( key, "[TypesSupported]", "7", "", "4" ) ; close handle RegCloseKey ( key ) ; add extender AddExtender ( "WWWNT34i.DLL" ) ; write event to Application log using custom source & event ID wntEventWrite ( "", "EvtTest", 262144, 100, "Additional info.") |
NOTE: using %1
in the text of the event description (see Example message file)
allows you to pass custom information to be included via the last parameter of the wntEventWrite function. Looking at
sample output below, you see that the description contains a concatenation of the two strings.
from Message Compiler help file
%% | Generates a single percent sign in the formatted message text. |
%\ | Generates a hard line break when it occurs at the end of a a line. |
%r | Generates a hard carriage return, without a trailing newline character. |
%b | Generates a space character in the formatted message text. This can be used to insure there are the appropriate number of trailing spaces in a message text line. |
%. | Generates a single period character in the formatted message text. This can be used to get a period at the beginning of a line without terminating the message definition. |
%! | Generates a single exclamation point in the formatted message text. This can be used to specify an exclamation point immediately after an insert. |
All of the above together generates the following event in the Application log:
Event Type: Information Event Source: EvtTest Event Category: None Event ID: 100 Date: 5/2/2002 Time: 1:48:04 PM User: N/A Computer: WIN2KTEST Description: This message came from the Message File. Additional info. |
Article ID: W15293
File Created: 2017:08:29:11:58:58
Last Updated: 2017:08:29:11:58:58