2011-09-23 118 views

回答

8

像這樣:

Set shell = CreateObject("WScript.Shell") 
shell.LogEvent 4, "Your Message Here" 

4是嚴重性級別。您可以通過MSDN瞭解有關LogEvent方法的更多信息。

+0

謝謝你的幫助。在哪裏寫日誌?我沒有找到它 – Emree

+0

@Emree - 它應該將它寫入事件查看器。你可以通過運行運行對話框中的'compmgmt.msc'來找到。查看Google的事件查看器。 – vcsjones

1

您可能只想寫入您自己的日誌文件。

檢查出我的鏈接更多的信息和細節

http://www.yeshaib.com/2010/08/vbscript-in-the-logging/

'---------------------------------------------------------------------- 
' 
' Please Enter Updates with date and name including line of Change 
'---------------------------------------------------------------------- 
'---------------------------------------------------------------------- 

set objShell = CreateObject("Wscript.Shell") 
set objFSO = CreateObject("Scripting.FileSystemObject") 

'--- Main Begins --------------------------------------- 

WriteToLog("Generic Log.vbs - Write This") 

'--- Main Ends ----------------------------------------- 

'--- Write to log -------------------------------------- 
Sub WriteToLog(strLogMessage) 
Const ForAppending = 8 
Const vbsName = "Generic Log" 

strLogFileName = "C:\GenericLog.log" 
strLogEntryTime = NOW 

'test whether file exists To either write/append to file 
if objFSO.FileExists(strLogFileName) Then 
Set objLogFileTransaction = objFSO.OpenTextFile(strLogFileName, ForAppending) 
Else 
Set objLogFileTransaction = objFSO.CreateTextFile(strLogFileName) 
End if 

objLogFileTransaction.WriteLine strLogEntryTime & chr(9) & chr(58) & chr(9) & vbsName & chr(9) & chr(58) & chr(9) & strLogMessage 
objLogFileTransaction.Close 
WScript.StdOut.WriteLine strLogMessage 
WScript.StdOut.WriteLine "" 
End Sub