Solved

VBScript write to custom event log on remote machine

Posted on 2004-08-06
6
12,977 Views
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]"
    NO_VALUE

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

Const EVENT_SUCCESS = 0
Const EVENT_ERROR = 1
Const EVENT_WARNING = 2
Const EVENT_INFORMATION = 4
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" ( http://support.microsoft.com/default.aspx?scid=kb%3BEN-US%3B257541 ) 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.

Thanks.
0
Comment
Question by:Mirfster
  • 2
6 Comments
 
LVL 22

Expert Comment

by:DarkoLord
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

Darko
0
 
LVL 8

Author Comment

by:Mirfster
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".

Thanks.
0
 
LVL 22

Accepted Solution

by:
DarkoLord earned 500 total points
ID: 11751948
Here is a DLL that can be used to call APIs:
http://www.borncity.de/WSHBazaar/WSHDynaCall.htm

Here is a sample code for writing to event log in VB:
http://www.mentalis.org/apilist/3E333A9BA6779769EB5D9723FB7FCAA7.html

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)

Darko
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now