Eventlog eines RemotePCs auslesen

  • hallo allerseits,

    ich bin der neue... und versuche gerade die ersten Schritte dieser neuen Scriptsprache (bin aber kein IT Neuling/ein paar Jahre DOS Scripting schon hinter mir!).

    hier mein Problem:

    ich möchte ein Script basteln, mit dem ich im ersten Schritt das Ereignisprotokoll eines Windows (2000,2003) Rechners auslesen kann. Ich habe ja auch schon etwas gefunden, aber mit dem Remotezugriff klappt es nicht (Zugriffsrechte sind da!!)

    Spoiler anzeigen
    [autoit]

    $sComputerName = "remotehost"

    [/autoit] [autoit][/autoit] [autoit]

    $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
    $objWMIService = $objSWbemLocator.ConnectServer _
    ($sComputerName, "root\cimv2", $sComputerName)
    $objWMIService.Security_.ImpersonationLevel = 3

    [/autoit] [autoit][/autoit] [autoit]

    $Query_Clause = "Select * FROM Win32_NTLogEvent WHERE Logfile = 'System' AND SourceName = 'eventlog'"
    If IsObj($objWMIService) Then
    $colItems = $objWMIService.ExecQuery ($Query_Clause)
    If IsObj($colItems) Then
    For $objEvent In $colItems
    $Output = ""
    $Output &= "Category: " & $objEvent.Category & @CRLF
    $Output &= "Computer Name: " & $objEvent.ComputerName & @CRLF
    $Output &= "Event Code: " & $objEvent.EventCode & @CRLF
    $Output &= "Message: " & $objEvent.Message & @CRLF
    $Output &= "Record Number: " & $objEvent.RecordNumber & @CRLF
    $Output &= "Source Name: " & $objEvent.SourceName & @CRLF
    $Output &= "Time Written: " & $objEvent.TimeWritten & @CRLF
    $Output &= "Event Type: " & $objEvent.Type & @CRLF
    $Output &= "User: " & $objEvent.User & @CRLF
    If MsgBox(64 + 4, "Entry Found:", $Output & @CRLF & @CRLF & "Continue?") = 7 Then Exit
    Next
    Else
    MsgBox(16, "Error", "$colItems is not an object.")
    EndIf
    Else
    MsgBox(16, "Error", "$objWMIService is not an object.")
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $sComputerName = "remotehost"

    [/autoit] [autoit][/autoit] [autoit]

    $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
    $objWMIService = $objSWbemLocator.ConnectServer _
    ($sComputerName, "root\cimv2", $sComputerName)
    $objWMIService.Security_.ImpersonationLevel = 3

    [/autoit] [autoit][/autoit] [autoit]

    $Query_Clause = "Select * FROM Win32_NTLogEvent WHERE Logfile = 'System' AND SourceName = 'eventlog'"
    If IsObj($objWMIService) Then
    $colItems = $objWMIService.ExecQuery ($Query_Clause)
    If IsObj($colItems) Then
    For $objEvent In $colItems
    $Output = ""
    $Output &= "Category: " & $objEvent.Category & @CRLF
    $Output &= "Computer Name: " & $objEvent.ComputerName & @CRLF
    $Output &= "Event Code: " & $objEvent.EventCode & @CRLF
    $Output &= "Message: " & $objEvent.Message & @CRLF
    $Output &= "Record Number: " & $objEvent.RecordNumber & @CRLF
    $Output &= "Source Name: " & $objEvent.SourceName & @CRLF
    $Output &= "Time Written: " & $objEvent.TimeWritten & @CRLF
    $Output &= "Event Type: " & $objEvent.Type & @CRLF
    $Output &= "User: " & $objEvent.User & @CRLF
    If MsgBox(64 + 4, "Entry Found:", $Output & @CRLF & @CRLF & "Continue?") = 7 Then Exit
    Next
    Else
    MsgBox(16, "Error", "$colItems is not an object.")
    EndIf
    Else
    MsgBox(16, "Error", "$objWMIService is not an object.")
    EndIf

    [/autoit]


    Vielleicht hat jemand ja eine Lösung - vielen Dank son mal im Voraus

    Gruß

    Peter

  • Herzlich Willkommen :)

    Wieso so kompliziert? müsste doch mit

    [autoit]

    _EventLog__Open($sServerName, $sSourceName)
    _EventLog__Read($hEventLog[, $fRead = True[, $fForward = True[, $iOffset = 0]]])

    [/autoit]

    auch funktionieren...

    Franz

    P.S. ich hatte den Avatar vorher :D:D

    ---
    In "Independence Day" konnten die Windows-Erdcomputer problemlos mit denen der Außerirdischen kommunizieren. Was sagt uns das über unseren lieben Bill Gates? :D
    ---

  • ich will keine Korinthen...

    Der Formhalber: _EventLog__Close nicht vergessen

    ;-))

    Stefan

    Also die beiden Zeilen funktionieren so ohnehin nicht. Sollte nur als Anfang zum suchen in der Hilfe dienen.. ;)

    ---
    In "Independence Day" konnten die Windows-Erdcomputer problemlos mit denen der Außerirdischen kommunizieren. Was sagt uns das über unseren lieben Bill Gates? :D
    ---

  • Hallo nochmal,
    herzlichen Dank für den kleinen Anschubs - mein Script läuft jetzt, ich muss zwar noch ein bischen Feintuning vornehmen, aber vom Prinzopt her geht's.

    Also noch mal Danke!

    Gruß
    Peter