Solved

EventLog handling

Posted on 2000-05-08
2
489 Views
Last Modified: 2013-12-03
Hey pals,

I'm trying to send some pretty simple messages to Event log file on NT 4.
Well, I tried just to use insertion strings parameter at ReportEvent
function but my boss got scared with "Description could not be found" messages. So I have no choice but to
create MC file.

Something went wrong with that - I performed all steps as written at MSDN
but no effect.
I understand there could be billions of reasons why it doesn't work, therefore I wonder if anyone could send me a simple example that would include : mc file, cpp file with ReportEvent function
call and step-by-step instructions how could I make dll from mc file.

Thanks in advance
0
Comment
Question by:schild
  • 2
2 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 200 total points
ID: 2790409
NOTE:

You have to create your own key under
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\

In my case (see event.reg below), the source name is EventSourceName("Event test").

EventMessageFile must point to your dll or exe file that contains the messages.

You may double-click on event.reg to write values into the registry, but you should modify the path to your program before.


;//------------------------------
;// EVENT.MC
;//------------------------------

MessageId=1000 SymbolicName=EVENT_HELLO
Language=English
Hello from the %1.
..

MessageId= SymbolicName=EVENT_BYE
Language=English
Bye from the %1.
..


//-------------------------------------
// EVENT.CPP
//-------------------------------------

#include <windows.h>
#include <iostream.h>
#include "event.h"

HANDLE  hEventLog=0;
LPCTSTR EventSourceName=TEXT("Event test");

void main(void)
{
   hEventLog=RegisterEventSource(NULL,EventSourceName);
   if(!hEventLog) {
      cout<<"Unable to register"<<endl;
      return;
   }

   LPCTSTR str[]={TEXT("TESTAPP")};
   ReportEvent(hEventLog,EVENTLOG_INFORMATION_TYPE,0,
      EVENT_HELLO,0,1,0,str,0);
   ReportEvent(hEventLog,EVENTLOG_ERROR_TYPE,0,
      EVENT_BYE,0,1,0,str,0);

   DeregisterEventSource(hEventLog);

}

rem ------------------------------------
rem MAKE.BAT
rem ------------------------------------
@echo off
mc event.mc
rc event.rc
cl event.cpp event.res advapi32.lib


-----------------------------------
event.reg
-----------------------------------

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\Event test]
"EventMessageFile"="D:\\TEMP\\EVENT\\EVENT.EXE"
"TypesSupported"=dword:00000007



0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2790417
There must be only the one dot after a message in the .MC file.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question