ProblemYou want to write an event to an event log. This can be useful if you want to document certain actions you've performed on a workstation. SolutionUsing a command-line interfaceThe following command writes an event to the Application event log with event ID 999 and source SysAdmin: > eventcreate /T <EventType> /ID <EventID> /L <LogName> /SO <EventSource> /D "<EventDescr>" For example: > eventcreate /T INFORMATION /ID 999 /L Application /SO SysAdmin /D "Restarting system after service pack install" Using VBScript' This code creates an event in the Application event log. ' ------ SCRIPT CONFIGURATION ------ strComputer = "\\<ComputerName>" ' e.g. wks01 strDescr = "<EventDescr>" ' e.g. Restarting computer after installing SP2 ' ------ END CONFIGURATION --------- Const EVENT_SUCCESS = 0 Const EVENT_ERROR = 1 Const EVENT_WARNING = 3 Const EVENT_INFO = 4 set objWSHShell = Wscript.CreateObject("Wscript.Shell") boolRC = objWSHShell.LogEvent(EVENT_INFO, strDescr, strComputer) if boolRC = TRUE then WScript.Echo "Successfully created event." else WScript.Echo "Failed to create event." end if DiscussionUsing a graphical user interfaceNone of the graphical tools (e.g., Event Viewer snap-in) allow you to create a custom event log message. Using a command-line interfaceTo create an event on a remote machine, specify the /S option followed by the host name for eventcreate. Use /U and /P, respectively, to specify an alternate user account and password with eventcreate. Using VBScriptWith WSH, you can create an event only in the Application log. The WMI Event Log classes do not support creating custom event log messages. See AlsoMS KB 324145, "HOW TO: Create Custom Events" |