Quoi, tu ne connais pas PB ? Va falloir parcourir tout le forum alors !

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 26-07-2012 08:11:58

El Ombre  
Membre
Date d'inscription: 24-05-2011
Messages: 8
Pépites: 49
Banque: 0

Observateur d'évènements windows

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

 

#2 26-07-2012 12:11:13

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

Re: Observateur d'évènements windows

Salut, un exemple en VB à traduire :

Code: vb

'-----------------------------------------------------------------------------------------
'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

N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

#3 26-07-2012 14:01:44

El Ombre  
Membre
Date d'inscription: 24-05-2011
Messages: 8
Pépites: 49
Banque: 0

Re: Observateur d'évènements windows

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

 

#4 26-07-2012 15:41:44

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

Re: Observateur d'évènements windows

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

Code: pb

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 :

Code: vb

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

N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

#5 08-08-2012 12:29:52

El Ombre  
Membre
Date d'inscription: 24-05-2011
Messages: 8
Pépites: 49
Banque: 0

Re: Observateur d'évènements windows

ok merci beaucoup

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22