如何使用vbscript编写事件日志

如何使用vbscript编写事件日志,vbscript,event-log,Vbscript,Event Log,我想在vbscript运行时写入事件日志。我怎样才能做到 谢谢你的帮助。这是旧的,但我确信仍然有效 您还需要权限才能写入事件日志,因此根据运行脚本的用户的不同,您可能有权访问或无权访问。类似于: Set shell = CreateObject("WScript.Shell") shell.LogEvent 4, "Your Message Here" 4是一个严重级别。您可以在上了解有关LogEvent方法的更多信息。您可能只想写入自己的日志文件 查看我的链接,了解更多信息和详细信息 谢

我想在vbscript运行时写入事件日志。我怎样才能做到


谢谢你的帮助。

这是旧的,但我确信仍然有效

您还需要权限才能写入事件日志,因此根据运行脚本的用户的不同,您可能有权访问或无权访问。

类似于:

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

4是一个严重级别。您可以在上了解有关
LogEvent
方法的更多信息。

您可能只想写入自己的日志文件

查看我的链接,了解更多信息和详细信息


谢谢你的帮助。在哪里写日志?我找不到it@Emree-应将其写入事件查看器。您可以通过在运行对话框中运行
compmgmt.msc
找到它。在谷歌上浏览一下事件查看器。谢谢你的帮助。在哪里写日志?我找不到
'----------------------------------------------------------------------
'
' 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