2014-02-12 43 views
0

我想要創建VBScript代碼來從Windows事件查看器中檢索特定的錯誤類型日誌,將它們保存在.txt文件中,並通過FTP或直接複製進行傳輸。從Windows事件查看器中提取錯誤日誌

我怎樣才能做到這一點?

我一直在做一些閱讀和偶然發現了這些頁面:

Main questionEventquery.vbs infoCopy file to remote computer

但我只是不明白如何做這個過程作爲一個整體。

在此先感謝。

回答

2

你可以很容易地通過啓動電源外殼來做到這一點。

一個簡單的方法來過濾事件日誌,在PowerShell中的錯誤是

Get-EventLog -LogName APPLICATION -EntryType Error 

如果需要,你可以很容易地使這個批處理腳本或VBScript的一部分。

要它重新定向到一個文本文件,馮可使用以下命令:

Get-EventLog -LogName APPLICATION -EntryType Error > Result.txt 

然後,你需要上傳文本文件到FTP

2

您可以使用事件日誌查詢WMI查詢。這裏是關於specific class的信息。

不知道你在找什麼,讓我們假設你想搜索應用程序事件日誌並記錄任何事件ID 1003.我使用On Error Resume Next作爲快速修復,所以它不會錯誤如果字段不包含數據。

On Error Resume Next 
LOG_FILE = "temp.txt" 

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent WHERE LogFile='Application'") 

For Each objEventin colItems 
    If objEvent.EventCode = 1003 Then  
     writeLog "Category: " & objEvent.Category 
     writeLog "Category String: " & objEvent.CategoryString 
     writeLog "Computer Name: " & objEvent.ComputerName 
     writeLog "Data: " & objEvent.Data 
     writeLog "Event Code: " & objEvent.EventCode 
     writeLog "Event Identifier: " & objEvent.EventIdentifier 
     writeLog "Insertion Strings: " & objEvent.InsertionStrings 
     writeLog "Logfile: " & objEvent.Logfile 
     writeLog "Message: " & objEvent.Message 
     writeLog "Record Number: " & objEvent.RecordNumber 
     writeLog "Source Name: " & objEvent.SourceName 
     writeLog "Time Generated: " & objEvent.TimeGenerated 
     writeLog "Time Written: " & objEvent.TimeWritten 
     writeLog "Type: " & objEvent.Type 
     writeLog "User: " & objEvent.User 
     writeLog "" 
    End If 
Next 

Sub writeLog(strText) 
    Dim objFSO, objLogFile 

    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objLogFile = objFSO.OpenTextFile(LOG_FILE, 8, True) 

    objLogFile.WriteLine strText 
    objLogFile.Close 

    Set objLogFile = Nothing 
    Set objFSO = Nothing 

End Sub 
-1

此行

對於每個objEventin colItems的

必須糾正這樣 對於每個objEvent在

+0

你能格式化colItems的答案更好一點? – pagep

相關問題