Aide et conseils concernant AutoIt et ses outils.
africanism
Niveau 4
Messages : 85 Enregistré le : mar. 24 juin 2008 20:05
Status :
Hors ligne
#1
Message
par africanism » ven. 02 mars 2012 13:30
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
Messages : 450 Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status :
Hors ligne
#2
Message
par GaRydelaMer » ven. 02 mars 2012 14:12
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
Tlem
Site Admin
Messages : 11830 Enregistré le : ven. 20 juil. 2007 21:00
Localisation : Bordeaux
Status :
Hors ligne
#3
Message
par Tlem » ven. 02 mars 2012 14:14
Dans cette partie du code, vous utilisez la variable $antivirus :
Code : Tout sélectionner
For $nome In $antivirus
$softwere_antivirus &= $nome.displayName &@CRLF
NextMais vous ne faite aucun contrôle pour savoir si l'objet n'est pas vide !!!
africanism
Niveau 4
Messages : 85 Enregistré le : mar. 24 juin 2008 20:05
Status :
Hors ligne
#4
Message
par africanism » ven. 02 mars 2012 14:35
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
NextMais 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
Messages : 85 Enregistré le : mar. 24 juin 2008 20:05
Status :
Hors ligne
#5
Message
par africanism » ven. 02 mars 2012 14:38
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
Messages : 450 Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status :
Hors ligne
#6
Message
par GaRydelaMer » ven. 02 mars 2012 14:42
Tester sur ma machine il me retourne aucune erreur et détecte bien mon anti-virus
Sinon tu remplaces ce morceaux par :
GaRydelaMer
Niveau 7
Messages : 450 Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status :
Hors ligne
#7
Message
par GaRydelaMer » ven. 02 mars 2012 15:31
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
Messages : 85 Enregistré le : mar. 24 juin 2008 20:05
Status :
Hors ligne
#8
Message
par africanism » ven. 02 mars 2012 16:19
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
Messages : 450 Enregistré le : mer. 18 mars 2009 22:12
Localisation : Montpellier
Status :
Hors ligne
#9
Message
par GaRydelaMer » ven. 02 mars 2012 17:10
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)