Le forum (ô combien francophone) des utilisateurs de Powerbuilder.
Pages: 1
Bonjour,
J'aimerai savoir si quelqu'un a des exemples de programmes qui permettent d'écrire des informations dans l'observateur d'évènements Windows 2003, Windows XP, Windows Vista, Windows 7.
Merci d'avance.
Hors ligne
Salut, un exemple en VB à traduire :
'----------------------------------------------------------------------------------------- 'AJOUTE UN EVENEMENT AU JOURNAL DES EVENEMENTS '----------------------------------------------------------------------------------------- ' 'Version : 1.0 'Auteur : Eric Juaneda 'Création : Jeudi 22 juin 2006 'Modification : '----------------------------------------------------------------------------------------- 'Ajoute un évènement dans le journal des Applications dont la source est WSH ' 'Pour plus d'information, ajouter à votre projet VB la référence 'à l'objet 'Windows Script Host Object Model' 'Emplacement : C:\WINNT\system32\wshom.ocx 'Bibliothèque : IWshRuntimeLibrary '----------------------------------------------------------------------------------------- Option Explicit Sub Main() Dim WshShell As Object Dim Message As String Dim msgType As Long Set WshShell = CreateObject("WScript.Shell") Message = "Mon message d'information" msgType = 2 '0 Success '1 Error '2 Warning '4 Information '8 Audit Success '16 Audit Failure WshShell.LogEvent msgType, Message ', machineName End Sub
Hors ligne
Ca fonctionne bien. Merci beaucoup.
Il y a eu juste un petit problème c'est qu'il me met WSH comme source de l'évènement.
Il y a -t-il un moyen de changer ça ?
Merci.
Hors ligne
Effectivement cette différence entre les versions de windows est évoquée ici : http://www.rgagnon.com/pbdetails/pb-0209.html
(In Windows NT/2000, events are logged in the Windows NT Event Log. In Windows 9x/Me, events are logged in WSH.log (located in the Windows directory).
Le code PB pour la route
CONSTANT integer SUCCESS = 0 CONSTANT integer ERROR = 1 CONSTANT integer WARNING = 2 CONSTANT integer INFORMATION = 4 CONSTANT integer AUDIT_SUCCESS = 8 CONSTANT integer AUDIT_FAILURE = 16 OLEObject wsh wsh = CREATE OLEObject wsh.ConnectToNewObject( "WScript.Shell" ) wsh.LogEvent( SUCCESS, "Application started" ) wsh.DisconnectObject() DESTROY wsh
Il faut peut-être regarder du coté la fonction EventLog.WriteEntry
Ou alors écrire directement les événements dans la base de registre : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\Mon appli
comme c'est fait ici : http://www.developpez.net/forums/d69269 … post466756
Sinon, un autre code à tester avec des fonctions de l'api :
Option Explicit Public Enum enmLogType LogError = 1& LogWarning = 2& LogInfo = 4& End Enum Public Enum enmErrLevel lInfo = &H60000000 lWarning = &HA0000000 lError = &HE0000000 End Enum Private Declare Function RegisterEventSource Lib "advapi32" Alias "RegisterEventSourceA" (ByVal lpUNCServerName As String, ByVal lpSourceName As String) As Long Private Declare Function DeregisterEventSource Lib "advapi32" (ByVal hEventLog As Long) As Long Private Declare Function ReportEvent Lib "advapi32" Alias "ReportEventA" (ByVal hEventLog As Long, ByVal wType As Long, ByVal wCategory As Long, ByVal dwEventID As Long, ByVal lpUserSid As Long, ByVal wNumStrings As Long, ByVal dwDataSize As Long, lpStrings As Any, lpRawData As Any) As Long Public Function WriteToEventViewer(sErrMsg As String, eEventType As LogEventTypeConstants, IDEvent As Integer, Optional sSourceName As String) As Boolean On Error Resume Next Dim lEventLogHwnd As Long Dim LogType As enmLogType Dim lEventID As Long Dim lCategory As Long Dim sServerName As String Dim lRet As Long WriteToEventViewer = True If sSourceName = "" Then sSourceName = App.EXEName lCategory = 0 sServerName = vbNullString If eEventType = vbLogEventTypeError Then LogType = LogError lEventID = IDEvent Or enmErrLevel.lError ElseIf eEventType = vbLogEventTypeInformation Then LogType = LogInfo lEventID = IDEvent Or enmErrLevel.lInfo ElseIf eEventType = vbLogEventTypeWarning Then LogType = LogWarning lEventID = IDEvent Or enmErrLevel.lWarning End If lEventLogHwnd = RegisterEventSource(lpUNCServerName:=sServerName, lpSourceName:=sSourceName) If lEventLogHwnd = 0 Then WriteToEventViewer = False Exit Function End If lRet = ReportEvent(hEventLog:=lEventLogHwnd, wType:=LogType, wCategory:=lCategory, dwEventID:=lEventID, lpUserSid:=0, wNumStrings:=1, dwDataSize:=0, lpStrings:=sErrMsg, lpRawData:=0) If lRet = False Then WriteToEventViewer = False End If DeregisterEventSource lEventLogHwnd End Function
Hors ligne
ok merci beaucoup
Hors ligne
Pages: 1