1. Ce site utilise des cookies. En continuant à utiliser ce site, vous acceptez l'utilisation des cookies. En savoir plus.
  2. Bonjour tout le monde ! Veillez consulter la Politique de forum pour comprendre nos règles, Merci a vous !
    Rejeter la notice

Détection en temps réel du changement d'état d'intégrité du centre de maintenance windows [Code S]

Discussion dans 'Windev' créé par Pascal, Fev 14, 2018.

  1. Pascal

    Pascal Active Member
    MEMBRE WX

    Inscrit:
    Fev 11, 2018
    Messages:
    82
    J'aime reçus:
    126
    Pour faire suite à mon post précédent sur l'obtention de l'état d'intégrité global du centre de maintenance Windows. Voici un nouveau code qui permet de détecter en temps réel tous changements d'état d'intégrité du centre de maintenance windows d'un poste local avec les fonctions "WscRegisterForChanges" et "WscUnRegisterChanges" de l'API "Wscapi.dll".

    [​IMG]
    La constante à déclarer :
    Code (Text):

    CONSTANT
       S_OK = 0x00000000 // Generic HRESULT for success (winerror.h).
    FIN
     
    Les fonctions à déclarer :
    Code (Text):

    // Résumé : The WscRegisterForChanges function registers a callback function to be run when Windows Security Center detects a change that could affect the health of one of the security providers.
    // Syntaxe :
    //[ <Résultat> = ] WscRegisterForChanges (<nCallbackAddress> est entier [, <nContext> est entier])
    //
    // Paramètres :
    //   nCallbackAddress (entier) : A memory address to the application-defined function to be called when a change to the WSC service occurs.
    //   nContext (entier - valeur par défaut=0) : A memory address to a variable to be passed as the nParameter parameter to the function pointed to by the nCallbackAddress parameter.
    // Valeur de retour :
    //    entier : //    If the function succeeds, the function returns a handle to the callback registration. If the function fails, the return value is zero.
    //
    // Exemple :
    // https://msdn.microsoft.com/en-us/library/bb432507(v=vs.85).aspx
    //
    PROCEDURE WscRegisterForChanges(LOCAL nCallbackAddress est un entier, nContext est un entier = Null)

    LOCAL
       WscCallbackRegistration est un entier = 0
       nResult est un entier = 0
       
    nResult = API("wscapi.dll","WscRegisterForChanges",0,&WscCallbackRegistration,nCallbackAddress,nContext)

    SI (nResult <> S_OK) ALORS WscCallbackRegistration = 0

    RENVOYER (WscCallbackRegistration)

    // Résumé : The WscUnRegisterChanges function cancels a callback registration that was made by a call to the WscRegisterForChanges function.
    // Syntaxe :
    //[ <Résultat> = ] WscUnRegisterChanges (<nRegistrationHandle> est entier)
    //
    // Paramètres :
    //   nRegistrationHandle (entier) : The handle to the registration context returned by the WscRegisterForChanges function.
    // Valeur de retour :
    //    entier : //    Returns S_OK if the function succeeds, otherwise returns an error code.
    //
    // Exemple :
    // https://msdn.microsoft.com/en-us/library/bb432508(v=vs.85).aspx
    //
    PROCEDURE WscUnRegisterChanges(LOCAL nRegistrationHandle est un entier)

    LOCAL
       nResult est un entier = 0
       
    nResult = API("wscapi.dll","WscUnRegisterChanges",nRegistrationHandle)

    RENVOYER (nResult)

    // Résumé : The function to be called when a change to the WSC service occurs.
    // Syntaxe :
    //[ <Résultat> = ] WscCallbackFunction (<nParameter> est entier)
    //
    // Paramètres :
    //   nParameter (entier) : A memory address to a variable.
    // Valeur de retour :
    //    booléen : //    Aucune
    //
    // Exemple :
    // Indiquez ici un exemple d'utilisation.
    //
    PROCEDURE WscCallbackFunction(LOCAL nParameter est un entier)

    Trace("Wsc change occurred !")

    RENVOYER(Vrai)
     
    La DLL à charger :
    Code (Text):

    gnMy_DLL est un entier = 0
    gnMy_DLL = ChargeDLL("Wscapi.dll")
     
    La variable globale à déclarer :
    Code (Text):

    gnHandle est un entier = 0
     
    Le code pour utiliser les fonctions "WscRegisterForChanges" et "WscUnRegisterChanges" (pour l'exemple mettre ce code dans un bouton) :
    Code (Text):

    LOCAL
       nResult est un entier = 0
       
    SI (gnHandle = 0) ALORS
       
       gnHandle = WscRegisterForChanges(&WscCallbackFunction,Null)
       SI (gnHandle <> 0) ALORS
           Trace("WscRegisterForChanges returned success.")
       SINON
           Trace("WscRegisterForChanges failed with error.")
       FIN
    SINON
       nResult = WscUnRegisterChanges(gnHandle)
       SI (nResult = S_OK) ALORS
           Trace("WscUnRegisterChanges returned success.")
           gnHandle = 0
       SINON
           Trace("WscUnRegisterChanges failed with error : " + NumériqueVersChaîne(nResult))
       FIN
    FIN
     
    La DLL à décharger :
    Code (Text):

    SI (gnMy_DLL) ALORS DéchargeDLL(gnMy_DLL)
     
    Voila c'est fini. Maintenant vous pouvez détecter tous changements d'état d'intégrité du centre de maintenance windows.

    Utilisation pour l'exemple :
    Cliquez une première fois sur votre bouton pour activer la fontion "WscRegisterForChanges".
    Désactivez puis ré-activez par exemple votre antivirus pour modifier l'état d'intégrité du centre de maintenance windows.
    Pour arreter la détection, cliquez une nouvelle fois sur votre bouton pour déactiver la fonction "WscRegisterForChanges" avec la fonction "WscUnRegisterChanges".


    Bon dev à vous tous !!!!

    Cordialement,
    Pascal

    PS :

    Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!

     
    cyberripper, suenodesign et joker aiment ça.
  2. suenodesign

    suenodesign Well-Known Member
    MEMBRE WX

    Inscrit:
    Jan 1, 2018
    Messages:
    507
    J'aime reçus:
    732
    Intéressent.
     
    Pascal apprécie ceci.

Partager cette page

Chargement...