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". 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!