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

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
africanism
Niveau 4
Niveau 4
Messages : 85
Enregistré le : mar. 24 juin 2008 20:05
Status : Hors ligne

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

#1

Message 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
GaRydelaMer
Niveau 7
Niveau 7
Messages : 450
Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status : Hors ligne

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

#2

Message 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
Avatar du membre
Tlem
Site Admin
Site Admin
Messages : 11830
Enregistré le : ven. 20 juil. 2007 21:00
Localisation : Bordeaux
Status : Hors ligne

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

#3

Message 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 !!!
Thierry

Rechercher sur le forum ----- Les règles du forum
Le "ça ne marche pas" est une conséquence commune découlant de beaucoup trop de raisons potentielles ...

Une idée ne peut pas appartenir à quelqu'un. (Albert Jacquard) tiré du documentaire "Copié n'est pas volé".
africanism
Niveau 4
Niveau 4
Messages : 85
Enregistré le : mar. 24 juin 2008 20:05
Status : Hors ligne

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

#4

Message 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 ?
africanism
Niveau 4
Niveau 4
Messages : 85
Enregistré le : mar. 24 juin 2008 20:05
Status : Hors ligne

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

#5

Message 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
GaRydelaMer
Niveau 7
Niveau 7
Messages : 450
Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status : Hors ligne

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

#6

Message 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
GaRydelaMer
Niveau 7
Niveau 7
Messages : 450
Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status : Hors ligne

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

#7

Message 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)
 
africanism
Niveau 4
Niveau 4
Messages : 85
Enregistré le : mar. 24 juin 2008 20:05
Status : Hors ligne

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

#8

Message 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)
GaRydelaMer
Niveau 7
Niveau 7
Messages : 450
Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status : Hors ligne

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

#9

Message 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)
Répondre