Solved

VBScript write to custom event log on remote machine

Posted on 2004-08-06
6
12,966 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

19 Experts available now in Live!

Get 1:1 Help Now