Hooking into Windows Event Viewer

Discussion in 'C++' started by Sean, Dec 6, 2006.

  1. Sean

    Sean Guest

    Here is a code I found that notifies if an event has been generated. I
    still can't find anything that would actually grab the event and export
    it a file which is what I am trying to do

    #include <windows.h>
    #include <stdio.h>


    BOOL notifyChange(LPCTSTR logSource)
    {
    BOOL bSuccess;
    HANDLE hEventLog, hEvent;
    DWORD dwWaitResult;

    hEventLog = OpenEventLog(NULL, // local machine
    logSource); // event log source name
    if (hEventLog == NULL)
    {
    printf("Could not open event log.");
    return FALSE;
    }

    hEvent = CreateEvent(NULL, // default security attributes
    FALSE, // no manual reset
    FALSE, // create as not signaled
    NULL); // no event name

    NotifyChangeEventLog(hEventLog, hEvent);

    dwWaitResult = WaitForSingleObject(hEvent, INFINITE);
    if (dwWaitResult == WAIT_FAILED)
    bSuccess = FALSE;
    else bSuccess = TRUE;

    CloseHandle(hEvent);
    CloseEventLog(hEventLog);
    return bSuccess;
    }

    What i am stuck on right now is the "LPCTSTR logSource". Where do I
    find the source of the log and how do I pass store it in a LPCTSTR.

    Can anyone give me a better suggestion. i am basically trying to grab
    any info that is generated by Windows Event logger (event ID, type of
    event, message, user, etc) to a text file.
     
    Sean, Dec 6, 2006
    #1
    1. Advertising

  2. Sean

    Salt_Peter Guest

    Sean wrote:
    > Here is a code I found that notifies if an event has been generated. I
    > still can't find anything that would actually grab the event and export
    > it a file which is what I am trying to do


    What follows is not C++, consider asking in a relevent newsgroup.
    Consult the following for a potential list of possibilities:
    [5.9] Which newsgroup should I post my questions?
    http://www.parashift.com/c -faq-lite/how-to-post.html

    >
    > #include <windows.h>
    > #include <stdio.h>
    >
    >
    > BOOL notifyChange(LPCTSTR logSource)
    > {
    > BOOL bSuccess;
    > HANDLE hEventLog, hEvent;
    > DWORD dwWaitResult;
    >
    > hEventLog = OpenEventLog(NULL, // local machine
    > logSource); // event log source name
    > if (hEventLog == NULL)
    > {
    > printf("Could not open event log.");
    > return FALSE;
    > }
    >
    > hEvent = CreateEvent(NULL, // default security attributes
    > FALSE, // no manual reset
    > FALSE, // create as not signaled
    > NULL); // no event name
    >
    > NotifyChangeEventLog(hEventLog, hEvent);
    >
    > dwWaitResult = WaitForSingleObject(hEvent, INFINITE);
    > if (dwWaitResult == WAIT_FAILED)
    > bSuccess = FALSE;
    > else bSuccess = TRUE;
    >
    > CloseHandle(hEvent);
    > CloseEventLog(hEventLog);
    > return bSuccess;
    > }
    >
    > What i am stuck on right now is the "LPCTSTR logSource". Where do I
    > find the source of the log and how do I pass store it in a LPCTSTR.
    >
    > Can anyone give me a better suggestion. i am basically trying to grab
    > any info that is generated by Windows Event logger (event ID, type of
    > event, message, user, etc) to a text file.
     
    Salt_Peter, Dec 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jacksgoogle
    Replies:
    0
    Views:
    1,770
    jacksgoogle
    May 11, 2005
  2. veeru
    Replies:
    1
    Views:
    1,570
  3. TS
    Replies:
    2
    Views:
    1,036
  4. Flynn

    Gallery Viewer viewer script

    Flynn, Feb 22, 2004, in forum: Javascript
    Replies:
    8
    Views:
    251
    John Flynn
    Feb 23, 2004
  5. planetthoughtful
    Replies:
    5
    Views:
    108
    David Mark
    Oct 13, 2008
Loading...

Share This Page