Login | |
|
 |
Writing to the Eventlog - 5/5/2005 9:19:08 PM
|
|
 |
|
| |
willem
Posts: 12
Score: 0
Joined: 4/25/2005
From: France
Status: offline
|
Hi co-scripters, I have a problem to tidy up my script to write to the eventlog. I am switching a lot between Windows2000 (my desktop) and the server, which is Windows2003. As the "eventcreate.exe" does not exist for Windows2000, I have to find another solution: -either find a way to define the Operating System dynamically (I now do it statically, but forget sometimes) -or use some other method to write the entries (I tried the class System.Diagnostics.Eventlog, see bottom of code, but probably making a mistake somewhere.) I want to use the EventID, which is not possible with the WShell.LogEvent method, which is what I am now using for Windows2000. I don't want to make a eventcreate.bat file on my desktop, that is definitely not a tidy way to do it. Can you help me with this? Here is what I have got now: Const icWINDOWS2000=1 Const icWINDOWSXP=2 '************************ '* Eventlog entry types '************************ Const icSUCCESS=0 Const icERROR=1 Const icWARNING=2 Const icINFORMATION=4 Const icAUDIT_SUCCESS=8 Const icAUDIT_FAILURE=16 dim iOS dim oShell, oEvtLog iOS=icWINDOWS2000 'this should be done dynamically! '*** error 33 to be logged somewhere in the program: ActionLog icERROR, "There is an error...", 33 '****************************************************************** '* Subroutine ActionLog * '****************************************************************** Sub ActionLog ( iSeverity, sDescription, iEvtID ) Const scSource="MyProgram" Dim bTryLog, bTryShell, strcommand '********************************** '* Echo to the console '********************************** Select Case iSeverity Case icSUCCESS sSeverity="SUCCESS" Case icERROR sSeverity="ERROR" Case icWARNING sSeverity="WARNING" Case icINFORMATION sSeverity="INFORMATION" Case icAUDIT_SUCCESS sSeverity="AUDIT_SUCCESS" Case icAUDIT_FAILURE sSeverity="AUDIT_FAILURE" Case Else sSeverity="" End Select If (bRunMode=bcRUN_DEV) Then wscript.echo sSeverity & ": " & sDescription '********************************** '* Log in the Event Log '********************************** bTryShell=False On Error Resume Next bTryShell=(oShell is Nothing) If bTryShell Then Set oShell=CreateObject("WScript.Shell") End If if (iOS=icWINDOWS2000) then oShell.LogEvent iSeverity, sDescription else strCommand = "eventcreate /T " & sSeverity & " /ID " & CStr(iEvtID) & " /L APPLICATION /SO " & scSource & " /D " & Chr(34) & sDescription & Chr(34) oShell.Run strcommand endif '************************************************** '* Log in the Event Log using Class - does not work '************************************************** ' bTryLog=False 'On Error Resume Next ' bTryLog=(oEvtLog is Nothing) ' If bTryLog Then ' Set oEvtLog=CreateObject("System.Diagnostics.EventLog") ' End If ' oEvtLog.WriteEntry scSource, sDescription, iSeverity, iEvtID End Sub ***************************** Willem
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|