[VBS] Code Error 800A0401 - Expected end of statement

neo2k2 Messages postés 126 Date d'inscription jeudi 16 janvier 2003 Statut Membre Dernière intervention 9 novembre 2009 - 29 août 2008 à 16:03
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 - 30 août 2008 à 14:35
Bonjour à toutes et tous!


J'ai un petit souci avec un programme en VBS que je développe pour mon travail.


Le programme sert à tester l'existence de signatures de programmes antivirus sur le réseau (sans utiliser la console d'administration).


Mon erreur d'execution provient du ping à la ligne 164...


Voila le code:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Program Name : chkAntivir       '
' Version : 1.0        '
' Licence : GNU/GPL       '
' Copyright : neo2k2              '
' Description : programme de verification des antivirus sur les pc du domaine '
'          '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


'
' modifier les variables %SERVER%, %MAIL%, %DOMAIN% avec vos propres parametres
'


Dim Fso
Dim FileRepInet ' Repertoire des fichiers  
Dim ScanTime, ScanEnd
'
ScanTime = "Scan began at: " & Now
'
'
LogTxt = "reportPC.log"   
LogXls = "FinalReport.xls"   
FileRepInet = "[file://\\%SERVER%\AntivirChk\ \\%SERVER%\AntivirChk\]"  
'
Call chkDomain()
Call rwxFile("[file://\\%SERVER%\AntivirChk\reportPC.log \\%SERVER%\AntivirChk\reportPC.log]", "Beginning scan at: " & Now)
'
Call chkAntivir("[file://\\%SERVER%\AntivirChk\finalListPC.log \\%SERVER%\AntivirChk\finalListPC.log]")
'
Call rwxFile("[file://\\%SERVER%\AntivirChk\reportPC.log \\%SERVER%\AntivirChk\reportPC.log]", "Scan ended at: " & Now)
'
Call xFile("[file://\\%SERVER%\AntivirChk\finalListPC.log \\%SERVER%\AntivirChk\finalListPC.log]")
'
ScanEnd = "Scan ended at: " & Now
'
Call SendMail(%SERVER%,%MAIL%, %MAIL%,"Antivirus report", ScanTime & " / " & ScanEnd & " - " & FileRepInet & LogXls)
'
MsgBox "Antivirus report", ScanTime & " / " & ScanEnd & " - " & FileRepInet & LogXls, vbInformation
'
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


 


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'                       '
' Principales procedures et fonctions utilisees par le programme chkDomain() '
'                       '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''




Sub chkAntivir(rTXT)
'
' Cette procedure lit le contenu du fichier texte et execute la requete
'
 'declaration des variables
 Dim tFSO
 Dim Ftxt, strComputer
 'instanciation
 Set tFSO = CreateObject("Scripting.FileSystemObject")
 'on instancie le fichier texte 
 Set Ftxt = tFSO.OpenTextFile(rTXT,1,False)
 'on parcourt chaque ligne du fichier texte
 Do While Not Ftxt.AtEndOfStream
       'le code pour traiter chaque ligne
       strComputer = Ftxt.Readline
       Call ChkFile(strComputer)
 Loop
 '
 Ftxt.Close
'
End Sub


Sub chkDomain()
'
' Cette procedure repertorie tous les PC du domaine mais exclut les serveurs et machines d'acquisition
'
 ' Declaration de la constante de lecture de l'arborescence de l'AD
 Const ADS_SCOPE_SUBTREE = 2
 ' Instanciation des objets pour la lecture de l'AD
 Set objConnection = CreateObject("ADODB.Connection")
 Set objCommand =   CreateObject("ADODB.Command")
 objConnection.Provider = "ADsDSOObject"
 objConnection.Open "Active Directory Provider"
 ' Instanciation de la connexion a l'AD
 Set objCOmmand.ActiveConnection = objConnection
 ' Commande de connexion a l'AD
 objCommand.CommandText = _
     "Select Name from 'LDAP://DC=%DOMAIN%,DC=com' Where objectClass='computer'"  
 objCommand.Properties("Page Size") = 1000
 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 ' Instanciation de la requete a executer sur l'AD
 Set objRecordSet = objCommand.Execute
 ' On se place sur le premier element trouve
 objRecordSet.MoveFirst
 ' On parcourt la liste des objets correspondant a la requete dans l'AD
 Do Until objRecordSet.EOF
  ' Appelle la procedure pour ecrire les objets dans un fichier
     Call wFile("[file://\\%SERVER%\AntivirChk\finalListPC.log \\%SERVER%\AntivirChk\finalListPC.log]", objRecordSet.Fields("Name").Value)
     ' Deplace le pointeur sur l'objet suivant dans l'AD
     objRecordSet.MoveNext
 Loop
'
End Sub


Sub rwxFile(rTXT, info)
'
' Cette fonction ecrit dans un fichier les informations qui lui sont passees en parametres
'
 Dim rFile 'Nom du fichier
 Dim FSys  'Declaration du File Scripting Object
 ' Instanciation de l'objet
 Set FSys = CreateObject("Scripting.FileSystemObject")
 ' Creation/Ouverture du fichier a ecrire
 Set rFile = FSys.OpenTextFile(rTXT,8,True)
 ' Ecrit l'information
 rFile.writeLine info
 ' Ferme l'objet texte
 rFile.Close
'
End Sub


Sub wFile(sTxt, wTxt)
'
' Cette procdure nettoie le fichier texte de donnees indesirees
'
 'declaration file system object
 Dim tFSO
 Dim Ftxt, tempTxt
 'instanciation
 Set tFSO = CreateObject("Scripting.FileSystemObject")
 'on instance le fichier texte 
 Set Ftxt = tFSO.OpenTextFile(sTxt,8,True)
 'on parcours chaque ligne du fichier texte
 tempTxt = Left(wTxt,4) If tempTxt "LAPT" Or tempTxt "POST" Then
  Ftxt.Writeline wTxt
 End If
 '
 Ftxt.Close
'
End Sub


Sub ChkFile(strComputer)
'
' Recherche sur la machine de fichiers de signature
'
 Dim cFile, tFile
 Dim Alert, Alert1, Alert2, Alert3, AlertPing
 '
 Alert = strComputer & ": "
 Alert1 = "Computer Associates"
 Alert2 = "Trend Micro"
 Alert3 = "no antivirus installed"
 AlertPing = strComputer & " did not respond to ping"
 '
 cFile = "\" & strComputer & "\c$\Program Files\CA\SharedComponents\ScanEngine\vet.dat"
 tFile = "\" & strComputer & "\c$\Program Files\Trend Micro\Client Server Security Agent\usrwl.dat"
 '
 Set fso = CreateObject("scripting.filesystemobject" )
 ' Appelle la procedure pour pinger les objets
 Set objShell = CreateObject("WScript.Shell") 
 'Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strComputer) ' methode moche mais qui fonctionne
 Set objRun = objShell.Run "ping -n 2 -w 1000 " & chr(34) & strComputer & chr(34), 0, True ' serait preferable car la fenetre DOS ne s'affiche pas mais ne marche pas
 'strPingResults = LCase(objExec.StdOut.ReadAll) ' a utiliser avec objShell.Exec
 strPingResults = LCase(objRun.StdOut.ReadAll)
 ' on va maintenant pinger chaque machine
 If InStr(strPingResults, "reply from") Then 
  'WScript.Echo VbCrLf & strTarget & " responded to ping."
  ' si le ping repond, on continue la verification
  If fso.FileExists(cFile) = True Then
   Call ChkDate(cFile)
      Alert = Alert & Alert1
  End If
  If fso.FileExists(tFile) = True Then
   Call ChkDate(tFile)
   Alert = Alert & Alert2
  End If  If fso.FileExists(cFile) False AND fso.FileExists(tFile) False Then
   '
   Call rwxFile("[file://\\%SERVER%\AntivirChk\reportPC.log \\%SERVER%\AntivirChk\reportPC.log]", Alert & " " & Alert3)
    Else
   '
   Call rwxFile("[file://\\%SERVER%\AntivirChk\reportPC.log \\%SERVER%\AntivirChk\reportPC.log]", Alert)
  End If
  '
 Else  ' sinon on ecrit la reponse dans le fichier
  'WScript.Echo VbCrLf & strTarget & " did not respond to ping."
  Call rwxFile("[file://\\%SERVER%\AntivirChk\reportPC.log \\%SERVER%\AntivirChk\reportPC.log]", AlertPing)
 End If 
'
End Sub


Sub xFile(stFile)
'
' Cette fonction permet de comparer la date du fichier avec la date du jour en tolrant une diffrence de 3 jours
'
 'dclaration file system object
 Dim fso
 'instanciation
 Set FSO = CreateObject("Scripting.FileSystemObject")
 'Suppression du fichier
 Set Ftxt = fso.GetFile(stFile)
 Ftxt.delete
End Sub


Sub SendMail(mserv, mfrom, mto, msub, mtxt)
 Set objEmail = CreateObject("CDO.Message")


 objEmail.From = mfrom
 objEmail.To = mto
 objEmail.Subject = msub 
 objEmail.Textbody = mtxt
 objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
         mserv 
 objEmail.Configuration.Fields.Item _
     ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 objEmail.Configuration.Fields.Update
 objEmail.Send
End Sub


Function ChkDate(stFichier)
'
' Cette fonction permet de comparer la date du fichier avec la date du jour en tolrant une diffrence de 3 jours
'
 Dim AlertDate, oldAlert, newAlert
 Dim oFSO,oFl
 '
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 If oFSO.FileExists(stFichier) Then
  Set oFl = oFSO.GetFile(stFichier)
    AlertDate = Day(oFl.DateLastModified)
    If DateDiff("d", Day(Now), AlertDate) >= 3 Then
     'MsgBox AlertDate, vbExclamation
     Call rwxFile("[file://\\%SERVER%\AntivirChk\reportPC.log \\%SERVER%\AntivirChk\reportPC.log]", "perime" & AlertDate)
    Else
     'MsgBox AlertDate, vbInformation
     Call rwxFile("[file://\\%SERVER%\AntivirChk\reportPC.log \\%SERVER%\AntivirChk\reportPC.log]", "a jour" & AlertDate)
    End If
    'MsgBox AlertDate
 End If
'
End Function



Merci d'avance
A voir également:

3 réponses

cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
29 août 2008 à 21:29
Je dirais qu'à priori il faut essayer ceci :

Set objRun = objShell.Run ( "ping -n 2 -w 1000 " & chr(34) & strComputer & chr(34), 0, True)

---- Sevyc64  (alias Casy) ----<hr size ="2" width="100%" /># LE PARTAGE EST NOTRE FORCE #    http://aide-office-vba.monforum.com/index.php
0
neo2k2 Messages postés 126 Date d'inscription jeudi 16 janvier 2003 Statut Membre Dernière intervention 9 novembre 2009 3
30 août 2008 à 14:19
Bonjour casy.

J'ai malheureusement déjà essayé sans succès. En fait il me semble que Set objRun = objShell.Run ( "ping -n 2 -w 1000 " & chr(34) & strComputer & chr(34), 0, True) retourne un booléen et non un objet.

J'ai testé en faisant un WScript.Echo et cela semble fonctionner donc je vais m'orienter sur:

objRun = objShell.Run "ping -n 2 -w 1000 " & chr(34) & strComputer & chr(34), 0, True
If objRun = 0 Then
   ...
Else
   ...
End If

J'aimerais comprendre par contre la différence entre
Set objRun = objShell.Exec("ping -n 2 -w 1000 " & chr(34) & strComputer)
et
Set objRun = objShell.Run("ping -n 2 -w 1000 " & chr(34) & strComputer & chr(34), 0, True)

en dehors du fait que Run me permette de spécifier d'autres paramètres...
0
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
30 août 2008 à 14:35
Alors là, je ne peut pas t'en dire plus.

Il faut se referer à la doc de WScript.Shell pour ça!

---- Sevyc64  (alias Casy) ----<hr size="2" width="100%" /># LE PARTAGE EST NOTRE FORCE #    http://aide-office-vba.monforum.com/index.php
0
Rejoignez-nous