Firewall manager

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Firewall manager

Message par ChaudEf »

Je comprends

Je ne veux pas te casser les pieds, mais tu penses que ceci peut faire l'affaire ?

http://stackoverflow.com/questions/1361 ... -a-machine

J'y ai compris que le titre...

En fait c'est incroyable, il y a des fonctions (http://www.purebasic.fr/french/viewtopi ... 83#p156783, merci falsam) pour détecter l'état du Firewall, si il est allumé ou éteint, et si il est réglé sur block ou allow, et a l'instant ou on installe un autre programme de Firewall, toutes les fonctions se faussent, car elles donnent seulement l'état du Firewall Windows, et celui-ci n'est pas activé, vu qu'un autre Firewall a été installé.
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
Zorro
Messages : 2186
Inscription : mar. 31/mai/2016 9:06

Re: Firewall manager

Message par Zorro »

apparemment ton code propose de savoir si il y a un Firewall actif ou pas (sans donner son identité )

c'est pas parce que ton code va t'indiquer que le firewall de windows est désactivé , que cela signifie
qu'il n'y a pas un autre firewall Actif a sa place ....



dans tout les cas , voici le code qui Active ou Desactive le firewall Windows
(a partir du moment ou c'est le seul Firewall sur le systeme )

Code : Tout sélectionner

;***********************************************
;Titre  :*desactive firewall
;Auteur  : Dobro
;Date  :22/08/2013
;Heure  :16:02:24
;Version Purebasic :  PureBasic 5.11 (Windows - x86)
;Version de l'editeur :EPB V2.40
; utiliser le mode Superviseur
;***********************************************
Declare  Parefeu(mode.c)


Parefeu(1)

end


Procedure Parefeu(mode.c)
	;désactive le firewall XP
	If mode = 0
		;etat$ = "?/c netsh firewall set opmode disable" ; XP
		etat$ = "?/c netsh advfirewall set currentprofile state off" ; Seven
		prg=RunProgram("cmd.exe",etat$,"",#PB_Program_Open | #PB_Program_Read )
		If prg
			While ProgramRunning(prg)
				Debug ReadProgramString(prg)
			Wend
			CloseProgram(prg)
		EndIf
		; *****************************
		Else
		; etat$ = "?/c netsh firewall set opmode enable"  ; XP
		etat$ = "?/c netsh advfirewall set currentprofile state on" ; Seven
		prg=RunProgram("cmd.exe",etat$,"",#PB_Program_Open | #PB_Program_Read )
		If prg
			While ProgramRunning(prg)
				Debug ReadProgramString(prg)
			Wend
			CloseProgram(prg)
		EndIf
		
	EndIf
EndProcedure

; EPB 

Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Firewall manager

Message par Ar-S »

En cherchant dans le registre (windows 10x64) j'ai trouve dans à cette clé :

Code : Tout sélectionner

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SharedAccess\Defaults\FirewallPolicy\DomainProfile
la valeur DWORD EnableFirewall sur 1 (mon firewall est activé) donc je me dis que sur 0 il doit être desactivé.
Tu as ta solution...
Si tu n'est pas sous W10, dans regedit, dans HKEY_LOCAL_MACHINE\SYSTEM\ cherche EnableFirewall
Voilou.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Firewall manager

Message par ChaudEf »

Merci Ar-S, c'est incroyable mais avec Eset, meme quand la valeur est a 0, le firewall est allume, et inversement.
Apparement il inscrit les reglages autre part.

En fait, dans le Action Center de Windows (wscui.cpl), il y a la liste des firewalls, et on peut choisir lequel on veut activer.
A priori, Windows ne s'amuse pas a checker les services et a deviner quel firewall est installe, mais au contraire, le firewall des qu'il s'installe, s'inscris quelque part, et ensuite windows lit la bas et affiche la liste de firewalls installes.

Ce qui reste a savoir est ou se trouve cette liste... J'ai fait un shot du registry, puis desinstalle eset, puis encore un shot, et ensuite j'ai utilise un programme de comparaison, mais il y avait environ 10000 changements, et j'ai pas eu le courage de les verifier un par un...
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Firewall manager

Message par celtic88 »

:)
pour détecter l antivirus et Pare-feu installer et ++++

Code : Tout sélectionner

;by celtic88 Dz(c)

DataSection
  CLSID_WbemLocator:
  Data.l  $4590F811
  Data.w  $1D3A
  Data.w  $11D0
  Data.b $89, $1F, $0, $AA, $0, $4B, $2E, $24
  IID_IWbemLocator:
  Data.l  $DC12A687
  Data.w  $737F
  Data.w  $11CF
  Data.b $88, $4D, $0, $AA, $0, $4B, $2E, $24
EndDataSection

#CLSCTX_INPROC_SERVER = $1
#WBEM_FLAG_RETURN_IMMEDIATELY = $10
#WBEM_FLAG_FORWARD_ONLY = $20
#WBEM_INFINITE = $FFFFFFFF
#RPC_C_IMP_LEVEL_IMPERSONATE = 3
#RPC_C_AUTHN_LEVEL_DEFAULT = 0
#RPC_C_AUTHN_WINNT =       10
#RPC_C_AUTHZ_NONE =          0
#RPC_C_AUTHN_LEVEL_CALL=3
#EOAC_NONE = 0

Procedure.l GetWindowsVersion()
  ; Return values .: Returns the binary version of the current OS.
  ;                            $1000 - Windows 10 / Windows Server 2016
  ;                            $603 - Windows 8.1 / Windows Server 2012 R2
  ;                            $602 - Windows 8 / Windows Server 2012
  ;                            $601 - Windows 7 / Windows Server 2008 R2
  ;                            $600 - Windows Vista / Windows Server 2008
  ;                            $502 - Windows XP 64-Bit Edition / Windows Server 2003 / Windows Server 2003 R2
  ;                            $501 - Windows XP
  lpVersionInformation.OSVERSIONINFO\dwOSVersionInfoSize=SizeOf(OSVERSIONINFO)
  If GetVersionEx_(lpVersionInformation)
    Debug (PeekS(@lpVersionInformation\szCSDVersion[0])) + " " + Str(lpVersionInformation\dwBuildNumber) 
    ProcedureReturn (lpVersionInformation\dwMajorVersion << 8) | lpVersionInformation\dwMinorVersion
  EndIf
EndProcedure

If CoInitializeEx_(0, #COINIT_MULTITHREADED) = #S_OK
  
  If CoInitializeSecurity_(0, -1, 0, 0, #RPC_C_AUTHN_LEVEL_DEFAULT, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, 0, 0) = #S_OK
    
    locator.IWbemLocator
    
    If CoCreateInstance_(?CLSID_WbemLocator, 0, #CLSCTX_INPROC_SERVER, ?IID_IWbemLocator, @locator) = #S_OK
      
      services.IWbemServices
      
      WmiNamespaceSCProduct.s = "root\SecurityCenter"
      WindowsVersion.w=GetWindowsVersion()
      If WindowsVersion > $502
        WmiNamespaceSCProduct.s + "2"
      EndIf
      
      If locator\ConnectServer(@WmiNamespaceSCProduct, 0, 0, 0, 0, 0, 0, @services) = #S_OK
        
        CoSetProxyBlanket_(services, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)
        
        Dim WmiClassSCProduct.s(2)
        WmiClassSCProduct(0)="AntiVirusProduct"
        WmiClassSCProduct(1)="AntiSpywareProduct"
        WmiClassSCProduct(2)="FirewallProduct"
        
        e.IEnumWbemClassObject  
        object.IWbemClassObject
        cvtVersion.VARIANT
        u.l
        
        For ii=0 To 2
          iWmiClassSCProduct.s="Select * From "+ WmiClassSCProduct(ii)
          If services\ExecQuery(@"WQL", @iWmiClassSCProduct, #WBEM_FLAG_RETURN_IMMEDIATELY | #WBEM_FLAG_FORWARD_ONLY, 0, @e) = #S_OK
            
            Debug WmiClassSCProduct(ii) + " :"
            
            While (e\Next(#WBEM_INFINITE, 1, @object, @u) = #S_OK)

              
              VariantInit_(@cvtVersion);            
              
              If object\Get(@"displayName", 0, @cvtVersion, 0, 0) = #S_OK
                Debug "displayName" + " : " + PeekS( cvtVersion\bstrVal)
                VariantClear_(@cvtVersion); 
              EndIf

                            object\Release()
              object=0
            Wend
            
            e\Release()
            e=0
          EndIf
        Next
        services\Release()
      EndIf
      
      locator\Release()
    EndIf
  EndIf   
  CoUninitialize_();
EndIf 
.....i Love Pb :)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Firewall manager

Message par celtic88 »

.....i Love Pb :)
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Firewall manager

Message par ChaudEf »

Merci celtic8, sur Windows 10 en 64 bit ca marche à merveille, mais sur seven 32 bits ca donne rien
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Firewall manager

Message par celtic88 »

ChaudEf a écrit :Merci celtic8, sur Windows 10 en 64 bit ca marche à merveille, mais sur seven 32 bits ca donne rien

service centre de sécurité windows est activé?
.....i Love Pb :)
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Firewall manager

Message par ChaudEf »

Comment je vérifie ca ?
En fait ca me retourne que une ligne, Windows 7 etc.
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Firewall manager

Message par celtic88 »

.....i Love Pb :)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Firewall manager

Message par celtic88 »

......
Dernière modification par celtic88 le mer. 10/mai/2017 11:57, modifié 1 fois.
.....i Love Pb :)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Firewall manager

Message par celtic88 »

vbs code :wink:

Code : Tout sélectionner

Const ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("Report.txt", ForAppending, True)
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\SecurityCenter2")
     For Each obj in oWMI.ExecQuery("Select * from AntiVirusProduct")
     If InStr(2, Hex(obj.productState), "1", 0) = 2 Then enabled = " [Enabled" Else enabled = " [Disabled"
     If InStr(4, Hex(obj.productState), "0", 0) = 4 Then updated = "|Updated] " Else updated = "|Outdated] "
     objLogFile.Write("AntiVirus: " _
         & obj.displayName _
         & Enabled _
         & Updated _
         & vbCrLf )
Next
For Each obj in oWMI.ExecQuery("Select * from AntiSpywareProduct")
     If InStr(2, Hex(obj.productState), "1", 1) = 2 Then enabled = " [Enabled" Else enabled = " [Disabled"
     If InStr(4, Hex(obj.productState), "0", 1) = 4 Then updated = "|Updated] " Else updated = "|Outdated] "
     objLogFile.Write("AntiSpyware: " _
         & obj.displayName _
         & Enabled _
         & Updated _
         & vbCrLf )
Next
For Each obj in oWMI.ExecQuery("Select * from FirewallProduct")
     If InStr(2, Hex(obj.productState), "1", 1) = 2 Then enabled = " [Enabled] " Else enabled = " [Disabled] "
     objLogFile.Write("Firewall: " _
         & obj.displayName _
         & Enabled _
         & vbCrLf )
Next
.....i Love Pb :)
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Firewall manager

Message par ChaudEf »

Meri beaucoup celtic88, tu a vraiment tape dans le mille, c'est exactement ce que j'avais besoin.
J'ai fait quelques tests sur Windows 7, et apparemment ça bloque sur cette ligne.

Code : Tout sélectionner

If locator\ConnectServer(@WmiNamespaceSCProduct, 0, 0, 0, 0, 0, 0, @services) = #S_OK

Le valeur de retour est quelque chose comme -250000.
Le centre de sécurité est bien activé.

Le code de la liste des antivirus est cool, mais a priori ca ne s'applique pas aux Firewalls.

Voila, si il y a une solution avec cette super fonction, sinon il faudra que je m'arrange autrement.
Merci encore.
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Firewall manager

Message par ChaudEf »

J'ai continue a m'amuser avec le code de celtic88, il est vraiment fantastique, en fin de compte le bug n'etait pas sur win7 mais sur l'ancienne version purebasic qui etait installe dessus.

J'ai maintenant un petit probleme, je ne sais pas si c'est un bug de purebasic ou une erreur que j'ai fait, mais cette procedure retourne une string, lorsque je la debug elle s'affiche bien, mais en messagerequester elle ne s'affiche pas, et mieux encore, si je met un messagerequester dans le code, meme le debug n'affiche plus rien.
Ca a l'air bizarre, je sais, donc je vous laisse tester. Il faut essayer le code comme ca, puis en decommentant la ligne du messagerequester.

Code : Tout sélectionner

;by celtic88 Dz(c)

#CLSCTX_INPROC_SERVER = $1
#WBEM_FLAG_RETURN_IMMEDIATELY = $10
#WBEM_FLAG_FORWARD_ONLY = $20
; #WBEM_INFINITE = $FFFFFFFF
#RPC_C_IMP_LEVEL_IMPERSONATE = 3
#RPC_C_AUTHN_LEVEL_DEFAULT = 0
#RPC_C_AUTHN_WINNT =       10
#RPC_C_AUTHZ_NONE =          0
#RPC_C_AUTHN_LEVEL_CALL = 3
#EOAC_NONE = 0

Procedure.l GetWindowsVersion()
	lpVersionInformation.OSVERSIONINFO\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
	If GetVersionEx_(lpVersionInformation)
		ProcedureReturn (lpVersionInformation\dwMajorVersion << 8) | lpVersionInformation\dwMinorVersion
	EndIf
EndProcedure

Procedure.s firwall()
	Define.s firewall
	
	locator.IWbemLocator : services.IWbemServices				
	WmiNamespaceSCProduct.s = "root\SecurityCenter"
	WindowsVersion.w = GetWindowsVersion()	
	If WindowsVersion > $502 : WmiNamespaceSCProduct.s + "2" : EndIf
	WmiClassSCProduct.s = "FirewallProduct"
	iWmiClassSCProduct.s = "Select * From "+ WmiClassSCProduct
	e.IEnumWbemClassObject : object.IWbemClassObject : cvtVersion.VARIANT : u.l
	VariantInit_(@cvtVersion)
	CoSetProxyBlanket_(services, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)

	If CoInitializeEx_(0, #COINIT_MULTITHREADED) = #S_OK
		If CoInitializeSecurity_(0, -1, 0, 0, #RPC_C_AUTHN_LEVEL_DEFAULT, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, 0, 0) = #S_OK
			If CoCreateInstance_(?CLSID_WbemLocator, 0, #CLSCTX_INPROC_SERVER, ?IID_IWbemLocator, @locator) = #S_OK
				If locator\ConnectServer(@WmiNamespaceSCProduct, 0, 0, 0, 0, 0, 0, @services) = #S_OK			
					If services\ExecQuery(@"WQL", @iWmiClassSCProduct, #WBEM_FLAG_RETURN_IMMEDIATELY | #WBEM_FLAG_FORWARD_ONLY, 0, @e) = #S_OK							
						While (e\Next(#WBEM_INFINITE, 1, @object, @u) = #S_OK)
							If object\Get(@"displayName", 0, @cvtVersion, 0, 0) = #S_OK
								firewall + PeekS(cvtVersion\bstrVal) + " ; "									
								VariantClear_(@cvtVersion)
							EndIf
						Wend						
						If object : object\Release() : object = 0 : EndIf
						e\Release() : e = 0
					EndIf
					services\Release()
				EndIf
				locator\Release()
			EndIf
		EndIf   
		CoUninitialize_()
	EndIf 
	ProcedureReturn Mid(firewall, 1, Len(firewall) - 3)
EndProcedure

firewall.s = firwall()
Debug firewall
;MessageRequester("", firewall)



DataSection
	CLSID_WbemLocator:
	Data.l  $4590F811
	Data.w  $1D3A
	Data.w  $11D0
	Data.b $89, $1F, $0, $AA, $0, $4B, $2E, $24
	IID_IWbemLocator:
	Data.l  $DC12A687
	Data.w  $737F
	Data.w  $11CF
	Data.b $88, $4D, $0, $AA, $0, $4B, $2E, $24
EndDataSection
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Firewall manager

Message par celtic88 »

:) hi bonjour
voila le code est corrigé

:x et ne changez rien sans savoir à quoi sert :mrgreen:

Code : Tout sélectionner

;by celtic88 Dz(c)

#CLSCTX_INPROC_SERVER = $1
#WBEM_FLAG_RETURN_IMMEDIATELY = $10
#WBEM_FLAG_FORWARD_ONLY = $20
; #WBEM_INFINITE = $FFFFFFFF
#RPC_C_IMP_LEVEL_IMPERSONATE = 3
#RPC_C_AUTHN_LEVEL_DEFAULT = 0
#RPC_C_AUTHN_WINNT =       10
#RPC_C_AUTHZ_NONE =          0
#RPC_C_AUTHN_LEVEL_CALL = 3
#EOAC_NONE = 0

Procedure.l GetWindowsVersion()
  lpVersionInformation.OSVERSIONINFO\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
  If GetVersionEx_(lpVersionInformation)
    ProcedureReturn (lpVersionInformation\dwMajorVersion << 8) | lpVersionInformation\dwMinorVersion
  EndIf
EndProcedure

Procedure.s firwall()
  Define.s firewall
  
  locator.IWbemLocator : services.IWbemServices            
  WmiNamespaceSCProduct.s = "root\SecurityCenter"
  WindowsVersion.w = GetWindowsVersion()   
  If WindowsVersion > $502 : WmiNamespaceSCProduct.s + "2" : EndIf
  WmiClassSCProduct.s = "AntiVirusProduct"
  iWmiClassSCProduct.s = "Select * From "+ WmiClassSCProduct
  e.IEnumWbemClassObject : object.IWbemClassObject : cvtVersion.VARIANT : u.l
  
  Protected Initializes_the_COM = CoInitializeEx_(0, #COINIT_MULTITHREADED)
  If Initializes_the_COM <> #S_FALSE And Initializes_the_COM <> #S_OK And Initializes_the_COM <> #RPC_E_CHANGED_MODE
    ProcedureReturn
  EndIf
  
  If CoInitializeSecurity_(0, -1, 0, 0, #RPC_C_AUTHN_LEVEL_DEFAULT, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE, 0) = #S_OK
    If CoCreateInstance_(?CLSID_WbemLocator, 0, #CLSCTX_INPROC_SERVER, ?IID_IWbemLocator, @locator) = #S_OK
      If locator\ConnectServer(@WmiNamespaceSCProduct, 0, 0, 0, 0, 0, 0, @services) = #S_OK         
        
        If CoSetProxyBlanket_(services, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE) = #S_OK ;<=== Sets the authentication information => ConnectServer 
          
          If services\ExecQuery(@"WQL", @iWmiClassSCProduct, #WBEM_FLAG_RETURN_IMMEDIATELY | #WBEM_FLAG_FORWARD_ONLY, 0, @e) = #S_OK                     
            
            While (e\Next(#WBEM_INFINITE, 1, @object, @u) = #WBEM_S_NO_ERROR)
              VariantInit_(@cvtVersion) ; <== Re -initializes the VARIANTARG 
              If object\Get(@"displayName", 0, @cvtVersion, 0, 0) = #S_OK
                
                firewall + PeekS(cvtVersion\bstrVal) + " ; "                           
                VariantClear_(@cvtVersion)
                
              EndIf
            Wend                  
            If object : object\Release() : object = 0 : EndIf
            e\Release() : e = 0
            
          EndIf
          
        EndIf
        services\Release()
      EndIf
      locator\Release()
    EndIf
  EndIf   
  
  If Initializes_the_COM = #S_OK
    CoUninitialize_()
  EndIf 
  ProcedureReturn Mid(firewall, 1, Len(firewall) - 3)
EndProcedure

firewall.s = firwall()
; Debug firewall
MessageRequester("", firewall)



DataSection
  CLSID_WbemLocator:
  Data.l  $4590F811
  Data.w  $1D3A
  Data.w  $11D0
  Data.b $89, $1F, $0, $AA, $0, $4B, $2E, $24
  IID_IWbemLocator:
  Data.l  $DC12A687
  Data.w  $737F
  Data.w  $11CF
  Data.b $88, $4D, $0, $AA, $0, $4B, $2E, $24
EndDataSection
.....i Love Pb :)
Répondre