EventLogQuery reader for remote computer?

前端 未结 1 1572
自闭症患者
自闭症患者 2021-01-02 14:45

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

 EventLogQuery eventsQuery = new EventLogQuery(\"Security\", PathType.LogName, queryStrin         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 15:38

    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;
            }
        }
    

    0 讨论(0)
提交回复
热议问题