using vbscript to write to the log AND specifying the event ID.

129 views
Skip to first unread message

Adam Sandler

unread,
Mar 16, 2005, 10:18:48 AM3/16/05
to
Hello,

I have the following example from the scripting center for writing to
the event log:

Const EVENT_SUCCESS = 0

Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, "Writing to the Log."
Set objShell = Nothing

This writes the string in quotes above to the log with an Event ID of
zero. If I want to use this example a few different ways, having all
those zeroes in the event log is tedious at best. I tried to change
Const EVENT_SUCCESS = to something other than 0 and the script errored
every single time.

If I can specify a string to be written to the event log, can I specify
the Event ID too? If so, how?

Thanks!!!

Torgeir Bakken (MVP)

unread,
Mar 16, 2005, 1:29:17 PM3/16/05
to
Adam Sandler wrote:

Hi

No, not with the builtin LogEvent method.

If you download and run regsvr32 on the free STAdmin.DLL available at

http://cwashington.netreach.net/downloads/com/event_log_manager.zip

you can do like this:

'--------------------8<----------------------
Const EVENT_WARNING = 2

Set oEventLog = CreateObject("STMAdmin.EventLog")
iEventID = 123
oEventLog.ReportEvent "MySource", iEventID, "Some description", EVENT_WARNING
'--------------------8<----------------------


Note the issue about eventMessageFile:
http://groups.google.co.uk/groups?threadm=e0ZgoV%2429GA.241%40uppssnewspub05.moswest.msn.net


You also have

oEventLog.Open("System") 'System or Application or Security
oEventLog.Close

but note this for the ReportEvent method from the documentation at
http://cwashington.netreach.net/main/library/stmadmin.html

<quote>
This method allows you to write a record into an event log. If the
source name isn’t a registered event log source then the event
will be written to the application event log.
</quote>

--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Adam Sandler

unread,
Mar 16, 2005, 2:12:58 PM3/16/05
to
As always... thanks for the great help!

Reply all
Reply to author
Forward
0 new messages