Improve company productivity with a Business Account.Sign Up


VBScript write to custom event log on remote machine

Posted on 2004-08-06
Medium Priority
Last Modified: 2010-05-18
I know that it is possible to create a custom event log on a remote machine using:

Const NO_VALUE = Empty
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\System\CurrentControlSet\Services\EventLog\[CUSTOM_EVENT_LOGNAME]\", "\\[REMOTE_COMPUTER]"

and you can write events to a remote Application event log using:

Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_ERROR, _
    "My custom message." , "\\[REMOTE_COMPUTER]"

But, how would you write a custom event to a custom event log on a remote machine?

FYI, I have already looked at "How To Write to the Windows NT/Windows 2000 System Log by Using the Windows Script Host" ( ) which does not provide any useful clues.

Need to make sure that this is in VBScript and since I need an answer quickly I will assign maximum points.

Question by:Mirfster
  • 2
LVL 22

Expert Comment

ID: 11742947
As far as I know there is no function in WScript/VBScript that you can use to report an event to log other than "Application"... The hard way would be to write the log file manually... However there are some APIs and DLLs that can be used for that


Author Comment

ID: 11751688
Can you inform me of the proper DLLs, with perhaps a sample script?

What I am trying to accomplish here is to log Success/Failures of pushing out MSI packages through GPO.  Active Directory does not provide logging, except on the target machines, as to if the "push" was successful or failed.

Since I create the MSIs, I would like to add custom code to the end of the installation that would simply log the [ProductName], [ComputerName], [Date], [Time] and a [Success/Failure Message] to an custom event log on a "Tracking" machine.

I can call DLLs that either reside on the local machine or embed them in the package.  So any information regarding the DLLs or APIs that leads me to accomplishing my goal would still result in an "Accepted Answer".

LVL 22

Accepted Solution

DarkoLord earned 2000 total points
ID: 11751948
Here is a DLL that can be used to call APIs:

Here is a sample code for writing to event log in VB:

Code would be something like this (maybe you need to fix it a little):

Dim UserWrap, LogHandle, retVal
Set UserWrap = CreateObject("DynamicWrapper")
UserWrap.Register "advapi32.dll", "RegisterEventSource", "i=ss", "f=s", "r=l"
UserWrap.Register "advapi32.dll", "ReportEvent", "i=lllllllsp","f=s","r=l"      'i hope that "p" is correct, if it doesnt work, try to change it so s(tring) or l(ong)
LogHandle = UserWrap.RegisterEventSource("servername", "customLogName")
retVal = UserWrap.ReportEvent(1, 1, 3, 0, 1, 0, "message", 0)


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

584 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question