Query remote event log using c#

Posted on 2008-11-03
Last Modified: 2013-12-17
Hi There,

I'm to query the event log on a remote machine. Specifically, I'm trying to query the (very large) System event log on a print server. I've used the Resource Kit tool "Dump Event Log" (dumpel.exe) in the past but I'd rather not rely on a separate program to generate the data.

I've got some code which queries the event log and returns the rows I want, sweet, however it takes far too long (50+ seconds) to run. Dumpel.exe only takes a few seconds so the method Im using cant be all that great.

The code Im using is attached. Apart from being slow, I prefer it than having an external app included in my project. If theres a way to embed an exe into my app that would be fine too (Im not sure there is tho Im still a beginner).

Maybe the code can be rewritten to run more efficiently or perhaps there's a whole different approach we can take here - I'm open to suggestions =)


ManagementScope scope;

            ManagementObjectSearcher searcher;

            ManagementObjectCollection queryCollection;

            ConnectionOptions options = new ConnectionOptions();

            string Server = "[print server]";

            string Username = "[Domain]\\[Admin account]";

            string Password = "[]";


            options.Username = Username;

            options.Password = Password;


            scope = new ManagementScope("\\\\" + Server + "\\root\\cimv2", options);

            SelectQuery query = new SelectQuery("select * from Win32_NTLogEvent where Logfile = 'System' and EventCode = 10 and SourceName = 'Print' and Type = 'information' and timegenerated >20081020 and timegenerated <20081025");


            searcher = new ManagementObjectSearcher(scope, query);



                queryCollection = searcher.Get();


            catch (Exception e)





Open in new window

Question by:Keyvee
    1 Comment
    LVL 41

    Accepted Solution

    That's right... the WMI method is a bit slow.    However, there is another technique using the .Net Framework's own EventLog class
    However, it's not that much faster for large event logs...  it can retrieve about 50,000 entries per minute (not a scientific measurement).   The speed decreases exponentionally as the size of the log file increases

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now