我希望在运行此vbscript时编写事件日志。我该怎么办?
感谢您的帮助。
答案 0 :(得分:8)
像这样:
Set shell = CreateObject("WScript.Shell")
shell.LogEvent 4, "Your Message Here"
4是严重性级别。您可以在MSDN上了解有关LogEvent
方法的更多信息。
答案 1 :(得分:1)
这已经过时但我确定仍然有效。
http://msdn.microsoft.com/en-us/library/b4ce6by3
您还需要能够写入事件日志的权限,这取决于运行您可能或我无法访问的脚本的用户。
答案 2 :(得分: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