EventLogQuery reader for remote computer?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 15:53:41

问题


I'm using this code to readmy own event Log from my win7 Computer.

 EventLogQuery eventsQuery = new EventLogQuery("Security", PathType.LogName, queryString);
 eventsQuery.ReverseDirection = true;
 EventLogReader logReader = new EventLogReader(eventsQuery);

However - I need to read the EventLog for a remote computer ( Lan - Same domain)

How can I do that ?


回答1:


http://msdn.microsoft.com/en-us/library/bb671200(v=vs.90).aspx

public void QueryRemoteComputer()
    {
        string queryString = "*[System/Level=2]"; // XPATH Query
        SecureString pw = GetPassword();

        EventLogSession session = new EventLogSession(
            "RemoteComputerName",                               // Remote Computer
            "Domain",                                  // Domain
            "Username",                                // Username
            pw,
            SessionAuthentication.Default);

        pw.Dispose();

        // Query the Application log on the remote computer.
        EventLogQuery query = new EventLogQuery("Application", PathType.LogName, queryString);
        query.Session = session;

        try
        {
            EventLogReader logReader = new EventLogReader(query);

            // Display event info
            DisplayEventAndLogInformation(logReader);
        }
        catch (EventLogException e)
        {
            Console.WriteLine("Could not query the remote computer! " + e.Message);
            return;
        }
    }


来源:https://stackoverflow.com/questions/7966993/eventlogquery-reader-for-remote-computer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!