473,388 Members | 1,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Reading Event Log

rth
I need to read the Security Event Log and then show the EVENTLOGRECORD as a
String. Reading records works fine but when I format the string that I'm
going to show the FormatMessage function generate an "Unhandled exception ...
(NTDLL.DLL) ... Access violation". I found a code sample on the net that I've
used to format the string but this generate the same problem. I need your
help. Now, I posted this code this funtion to format the EVENTLOGRECORD data,
any suggestions?.

BOOL GetDescription(char *Log, EVENTLOGRECORD *EventLogRecPtr, char *tmpStr)
{
int i=0,I ,j;
unsigned long FileNameModuleSize = 100;
char tmp[200];
HKEY nKeyHandle=0;
BYTE FileNameModule[100],expbuffer[BUFFER_SIZE];
LPTSTR message, *strings, AllocedStr[20] ;
LPVOID lpBuffer;

sprintf(tmp,"SYSTEM\\CurrentControlSet\\Services\\ EventLog\\%s\\%s",
Log, (LPBYTE)EventLogRecPtr + sizeof(EVENTLOGRECORD));

RegOpenKey(HKEY_LOCAL_MACHINE,(LPTSTR) tmp,&nKeyHandle);

RegQueryValueEx(nKeyHandle,"EventMessageFile",NULL ,NULL,
FileNameModule, &FileNameModuleSize);

ExpandEnvironmentStrings((LPCTSTR)FileNameModule, (LPSTR)expbuffer,
BUFFER_SIZE);
RegCloseKey(HKEY_LOCAL_MACHINE);

if (nKeyHandle)
{
message = (LPTSTR)((LPBYTE)EventLogRecPtr + EventLogRecPtr->StringOffset);

strings = (char**)malloc(sizeof(LPVOID)*EventLogRecPtr->NumStrings);

for (j = 0; j < EventLogRecPtr->NumStrings;j++)
{
if (strstr(message,"%%"))
{
(LPTSTR) strings[j] = GetParameterMsg(message, tmp);
AllocedStr[i++] = strings[j];
}
else
(LPTSTR) strings[j] = message;

message = message + strlen(message) +1;

}

HMODULE hlib = LoadLibraryEx((LPCTSTR)expbuffer, NULL,
LOAD_LIBRARY_AS_DATAFILE);

I=FormatMessage( FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY,
hlib,
EventLogRecPtr->EventID,
0,
(LPTSTR)&lpBuffer,
sizeof(lpBuffer),
(LPTSTR *)(strings));

if( I == 0)
{
while (i >0)
{
free(AllocedStr[--i]);
}

MissatgesError();

if(lpBuffer == NULL)
LocalFree( lpBuffer );
return False;
}

strcpy(tmpStr, (char *) lpBuffer);

for(I = 0; I< (int) strlen(tmpStr);I++)
{
if((tmpStr[i] != 0) && ((tmpStr[i] > 0 && tmpStr[i] < 32)))
tmpStr[i] = 32;
}

LocalFree( lpBuffer );
FreeLibrary(hlib);
return True;
}
return False;
}
Nov 17 '05 #1
0 795

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Scott Shaw | last post by:
Hi all, I was wondering if you could help out with this problem that I am having. What I am trying to do is detect keyboard input in a while loop without halting/pausing the loop until the key is...
3
by: Catherine Lynn Smith | last post by:
I'm looking through the client side javascript reference and there's some mighty useful information in here, but it is not very specific on 'reading' information from event handlers. In the...
3
by: Bwalker252 | last post by:
Anyone with experience with this property? I seem unable to change it. I've been trying to use it with a simple text box, using the property options in the properties window and I've also tried...
4
by: Greg Smith | last post by:
I have an old application that analyzes the data in the event log on one of our servers. I would like to convert it to C#. Does anybody know of any examples of reading the event log on a remote...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
0
by: Manfred Braun | last post by:
Hi All, I have a problem reading queue-messages async. My QueueReader has a Start() and a Stop() method and if my app starts, it calls Start(). The problem is, that there are possibly several...
1
by: hecsan07 | last post by:
Hey I am trying to read the Windows Event Logc. In fact, I am able to read the Event Log. My problem is that I am reading and filtering a large log and it takes a very very very very long time...
2
by: Robert Scheer | last post by:
Hi. I need to write a service that writes to a database the time of the logon and logoff of the users. Our users logs on Active Directory and some can also log as local administrators. The...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
1
by: stevedub | last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.