Page 1 sur 1

[..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 13:30
par africanism
bonjour,

je vient vers vous car je bloque

voila je vient de faire un script pour detecte l'antivirus installe sur des pc.
ca fonction quand il y a un antivirus par contre j'ai une erreur quand il n'en a pas.

Avez vous une idée merci.
voici le code.

Code : Tout sélectionner

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=C:\Users\cardeirad\Desktop\Detect_antivirus.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;code verification antivirus sur pc
#Include <Date.au3>



if @OSVersion = "WIN_XP" Then
$softwere_antivirus = ""&@CRLF
$Serv = ObjGet("winmgmts:\\" &@ComputerName& "\root\SecurityCenter"); pour windows xp
 $antivirus = $Serv.ExecQuery("Select * from AntiVirusProduct")
For $nome In $antivirus
        $softwere_antivirus &= $nome.displayName &@CRLF
Next
FileWriteLine("c:\Public\detect.txt", _now() & "        " & @ComputerName & "     " &  $nome.displayName )
EndIf




If @OSVersion = "WIN_7" Then
    $softwere_antivirus = ""&@CRLF
$Serv = ObjGet("winmgmts:\\" &@ComputerName& "\root\SecurityCenter2"); pour windows 7
 $antivirus = $Serv.ExecQuery("Select * from AntiVirusProduct")
For $nome In $antivirus
        $softwere_antivirus &= $nome.displayName &@CRLF
Next
FileWriteLine("c:\Public\detect.txt", _now() & "        " & @ComputerName & "     " &  $nome.displayName )
EndIf
Exit
 
Merci a vous

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 14:12
par GaRydelaMer
Bonjour

je pense que un truc du genre va marcher j'ai pas tester.

J'ai repris votre code pour plus de clarté

Code : Tout sélectionner

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=C:\Users\cardeirad\Desktop\Detect_antivirus.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;code verification antivirus sur pc
#Include <Date.au3>

Global $software_antivirus = ""
Global $sObj = "winmgmts:\\" & @ComputerName & "\root\SecurityCenter"
If @OSVersion = "WIN_7" Then $sObj &= "2"

Global $Serv = ObjGet($sObj)
Global $oRs = $Serv.ExecQuery("Select * from AntiVirusProduct")
If $oRs.EOF Then
    $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & "Aucun d'installé" & @CRLF
Else
    For $name In $oRs
        $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & $name.displayName & @CRLF
    Next
EndIf
FileWriteLine("c:\Public\detect.txt", $software_antivirus & @CRLF)

Exit

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 14:14
par Tlem
Dans cette partie du code, vous utilisez la variable $antivirus :

Code : Tout sélectionner

For $nome In $antivirus
        $softwere_antivirus &= $nome.displayName &@CRLF
Next
Mais vous ne faite aucun contrôle pour savoir si l'objet n'est pas vide !!!

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 14:35
par africanism
Tlem a écrit :Dans cette partie du code, vous utilisez la variable $antivirus :

Code : Tout sélectionner

For $nome In $antivirus
        $softwere_antivirus &= $nome.displayName &@CRLF
Next
Mais vous ne faite aucun contrôle pour savoir si l'objet n'est pas vide !!!
merci pour la reponse mais comment on fait ?

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 14:38
par africanism
GaRydelaMer a écrit :Bonjour

je pense que un truc du genre va marcher j'ai pas tester.

J'ai repris votre code pour plus de clarté

Code : Tout sélectionner

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=C:\Users\cardeirad\Desktop\Detect_antivirus.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;code verification antivirus sur pc
#Include <Date.au3>

Global $software_antivirus = ""
Global $sObj = "winmgmts:\\" & @ComputerName & "\root\SecurityCenter"
If @OSVersion = "WIN_7" Then $sObj &= "2"

Global $Serv = ObjGet($sObj)
Global $oRs = $Serv.ExecQuery("Select * from AntiVirusProduct")
If $oRs.EOF Then
    $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & "Aucun d'installé" & @CRLF
Else
    For $name In $oRs
        $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & $name.displayName & @CRLF
    Next
EndIf
FileWriteLine("c:\Public\detect.txt", $software_antivirus & @CRLF)

Exit
merci pour ta reponse mais j'ai une erreur

Code : Tout sélectionner

detect antivirus_bis.au3 (15) : ==> The requested action with this object has failed.:
If $oRs.EOF Then
If $oRs.EOF ^ ERROR

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 14:42
par GaRydelaMer
Tester sur ma machine il me retourne aucune erreur et détecte bien mon anti-virus

Sinon tu remplaces ce morceaux par :

Code : Tout sélectionner

If Not isObj($oRS) Then

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 15:31
par GaRydelaMer
Alors après avoir lu la doc sur msdn, on obtient dans tous les cas un objet "SWbemObjectSet"

et si il trouve pas ton expression, il retourne un objet Erreur, donc tu vas devoir traiter les erreurs autrement:

Code : Tout sélectionner

Global $n_MyError = 0, $o_MyError = ObjEvent("AutoIt.Error", "ObjCom_Err")

Func ObjCom_Err()
    $n_MyError = Hex($o_MyError.number, 8)
EndFunc   ;==>ObjCom_Err

If $oRs.Count = 0 Then
    If $n_MyError > 0 Then $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & "Aucun Anti-Virus d'installé" & @CRLF
    $n_MyError = 0
Else
    For $name In $oRs
        $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & $name.displayName & @CRLF
    Next
EndIf
ConsoleWrite($software_antivirus)
 

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 16:19
par africanism
GaRydelaMer a écrit :Alors après avoir lu la doc sur msdn, on obtient dans tous les cas un objet "SWbemObjectSet"

et si il trouve pas ton expression, il retourne un objet Erreur, donc tu vas devoir traiter les erreurs autrement:

Code : Tout sélectionner

Global $n_MyError = 0, $o_MyError = ObjEvent("AutoIt.Error", "ObjCom_Err")

Func ObjCom_Err()
    $n_MyError = Hex($o_MyError.number, 8)
EndFunc   ;==>ObjCom_Err

If $oRs.Count = 0 Then
    If $n_MyError > 0 Then $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & "Aucun Anti-Virus d'installé" & @CRLF
    $n_MyError = 0
Else
    For $name In $oRs
        $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & $name.displayName & @CRLF
    Next
EndIf
ConsoleWrite($software_antivirus)
 
Bon j'ai reprit la code
mais quand il n'y a pas d'antivirus il me fait une ligne blanche dans le fichier texte.
dans le msgbox pareil.

pensez vous qu'il y a un moyen d'ecrire quelque chose plutot que le blanc.

voici le code.

Code : Tout sélectionner

#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;code verification antivirus sur pc
#Include <Date.au3>
Global $n_MyError = 0, $o_MyError = ObjEvent("AutoIt.Error", "ObjCom_Err")

Func ObjCom_Err()
    $n_MyError = Hex($o_MyError.number, 8)
EndFunc   ;==>ObjCom_Err

Global $software_antivirus = ""
Global $sObj = "winmgmts:\\" & @ComputerName & "\root\SecurityCenter"

If @OSVersion = "WIN_7" Then $sObj &= "2"

Global $Serv = ObjGet($sObj)
Global $oRs = $Serv.ExecQuery("Select * from AntiVirusProduct")
If $oRs.Count = 0 Then
    If $n_MyError > 0 Then $software_antivirus &= _Now() & @TAB & @TAB & @ComputerName & @TAB & "Aucun Anti-Virus d'installé" & @CRLF
    $n_MyError = 0
Else
    For $name In $oRs
        $software_antivirus &=  _Now() & @TAB & @TAB & @ComputerName & @TAB & $name.displayName & @CRLF
    Next
EndIf
FileWriteLine("c:\Public\detect2.txt", $software_antivirus)
MsgBox (4096,"",$software_antivirus,10)

Re: [..] Pb code quand ne détecte pas d'antivirus .

Posté : ven. 02 mars 2012 17:10
par GaRydelaMer
Voila finalement c'est encore plus simple

Code : Tout sélectionner

#Include <Date.au3>
Global $n_MyError = 0, $o_MyError = ObjEvent("AutoIt.Error", "ObjCom_Err")

Func ObjCom_Err()
    $n_MyError = Hex($o_MyError.number, 8)
EndFunc   ;==>ObjCom_Err

Global $software_antivirus = _Now() & @TAB & @TAB & @ComputerName & @TAB & "Aucun Anti-Virus d'installé" & @CRLF
Global $sObj = "winmgmts:\\" & @ComputerName & "\root\SecurityCenter"

If @OSVersion = "WIN_7" Then $sObj &= "2"

Global $Serv = ObjGet($sObj)
Global $oRs = $Serv.ExecQuery("Select * from AntiVirusProduct")
For $name In $oRs
    $software_antivirus =  _Now() & @TAB & @TAB & @ComputerName & @TAB & $name.displayName & @CRLF
Next
FileWriteLine("c:\Public\detect2.txt", $software_antivirus)
MsgBox (4096, "", $software_antivirus, 10)