Code : Tout sélectionner
Set fwMgr = CreateObject("HNetCfg.FwMgr")

Code : Tout sélectionner
Set fwMgr = CreateObject("HNetCfg.FwMgr")
Code : Tout sélectionner
;-------------------------------------------------
;- Activation / Désactivation du Pare-Feu Windows
;-------------------------------------------------
EnableExplicit
; Variables du programme
Define.l objShell
Define.l objFwMgr
Define.b bResult
Define.l oProfile
; Activation des exceptions DispHelper
dhToggleExceptions(#True)
; Créé l'objet Shell
objShell = dhCreateObject("Shell.Application")
If objShell
; Vérifie que le service Pare-Feu Windows est démarré
dhGetValue("%b", @bResult, objShell, "IsServiceRunning(%T)", @"SharedAccess")
If bResult
; Créé l'objet Windows (Firewall)
objFwMgr = dhCreateObject("HNetCfg.FwMgr")
If objFwMgr
; Récupère les paramêtres locaux du Pare-Feu Windows
dhGetValue("%o", @oProfile, objFwMgr, ".LocalPolicy.CurrentProfile")
If oProfile
; Vérifie si le Pare-Feu Windows est actif
dhGetValue("%b", @bResult, oProfile, ".FirewallEnabled")
If bResult
; Le Pare-Feu Windows est activé
If MessageRequester("Information", "Le Pare-Feu est activé." + #LF$ + "Voulez-vous le désactiver ?", #MB_OKCANCEL) = #IDOK
dhPutValue(oProfile, ".FirewallEnabled = %b", #False)
EndIf
Else
; Le Pare-Feu Windows est désactivé
If MessageRequester("Information", "Le Pare-Feu est désactivé." + #LF$ + "Voulez-vous l'activer ?", #MB_OKCANCEL) = #IDOK
dhPutValue(oProfile, ".FirewallEnabled = %b", #True)
EndIf
EndIf
EndIf
; Libère l'objet Pare-Feu (FireWall)
dhReleaseObject(objFwMgr)
EndIf
Else
; Démarre le service Pare-Feu Windows
dhCallMethod(objShell, ".ServiceStart(%T, %b)", @"SharedAccess", #True)
EndIf
; Libère l'objet Shell
dhReleaseObject(objShell)
EndIf
Code : Tout sélectionner
Procedure EnableFirewall(bool.b)
Protected objShell.l, objFwMgr.l, bResult.b
objShell = dhCreateObject("Shell.Application")
If objShell
dhGetValue("%b", @bResult, objShell, "IsServiceRunning(%T)", @"SharedAccess")
If bResult
objFwMgr = dhCreateObject("HNetCfg.FwMgr")
If objFwMgr
dhPutValue(objFwMgr, ".LocalPolicy.CurrentProfile.FirewallEnabled = %b", bool)
dhReleaseObject(objFwMgr)
EndIf
EndIf
dhReleaseObject(objShell)
EndIf
EndProcedure
Procedure.b IsFirewallEnabled()
Protected objShell.l, objFwMgr.l, bResult.b
objShell = dhCreateObject("Shell.Application")
If objShell
dhGetValue("%b", @bResult, objShell, "IsServiceRunning(%T)", @"SharedAccess")
If bResult
objFwMgr = dhCreateObject("HNetCfg.FwMgr")
If objFwMgr
dhGetValue("%b", @bResult, objFwMgr, ".LocalPolicy.CurrentProfile.FirewallEnabled")
dhReleaseObject(objFwMgr)
EndIf
EndIf
dhReleaseObject(objShell)
EndIf
ProcedureReturn bResult
EndProcedure
; Active/Désactive le Firewall
#ComTrue = -1
EnableFirewall(#ComTrue - IsFirewallEnabled())
Code : Tout sélectionner
Import "advpack.lib"
IsNTAdmin(dwReserved.l, *lpdwReserved)
EndImport
Debug IsNTAdmin(#Null, #Null)