Un peux d'aide sur un VBS

cs_azame Messages postés 1 Date d'inscription jeudi 12 février 2009 Statut Membre Dernière intervention 3 novembre 2009 - 3 nov. 2009 à 16:45
raymix Messages postés 4 Date d'inscription jeudi 10 décembre 2009 Statut Membre Dernière intervention 4 janvier 2010 - 10 déc. 2009 à 15:38
Bonjour à tous ,

Je suis Novice en VBS j'ai réaliser un script de sauvegarde que voici

------------------------------------------------------------
------------------------------------------------------------
Q1 = Msgbox ("Voulez vous sauvegarder ?",vbyesno,"")
If Q1 Vbyes then Q1 msgbox ("attention fermeture d'outlook ?",vbyesno,"confirmation")
if Q1 vbno then Q2 msgbox ("etes vous sur de vouloir quitter ?",vbyesno,"comfirmation")
if Q2 = vbyes then wscript.quit
If Q1 vbno then Q2 msgbox ("etes vous sur de vouloir quitter ?",vbyesno,"comfirmation")
if Q2 = vbyes then wscript.quit
Dim SO
Set fSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "\\peuwfs00017\Backup\MTM Ressoources\robocopy.exe","C:\WINDOWS\system32"
set shl = createobject ("wscript.shell")
shl.run "cmd /c taskkill /F /IM outlook.exe"
Function Lpad (MyValue, MyPadChar, MyPaddedLength)
Lpad = string(MyPaddedLength - Len(MyValue),MyPadChar) & MyValue
End Function
set owsh = createobject("wscript.shell")
sSourceFolder = "D:\users\%username%"
sDestinationFolder = "\\peuwfs00017\Backup\%username%"
sCommand = "robocopy """
sCommand = sCommand & sSourceFolder & """ "
sCommand = sCommand & sDestinationFolder & " "
sCommand = sCommand & " /E /S /R:5 /W:10"
sCommand = sCommand & " /LOG+:" & "\\peuwfs00017\Backup\%username%" & year(now) & Lpad(month(now), "0", 2) & Lpad(day(now), "0", 2) & "Sauvegarde.log"
set x = owsh.exec(sCommand)
While Encours=True
doevents
Wend
sMsg = "Sauvegarde terminée"
MsgBox sMsg, 64, sTitle

'Create an Outlook object
Dim Outlook 'As New Outlook.Application
Set Outlook = CreateObject("Outlook.Application")
'Create e new message
Dim Message 'As Outlook.MailItem
Set Message = Outlook.CreateItem(olMailItem)
With Message
.Subject = "Sauvegarde MTM"
'Set destination email address
.Recipients.Add ("asnel.felicien@intl.pepsico.com")
.Body = "Sauvegarde Terminer"
'Send the message
.Send
End With
-----------------------------------------------------------------------
-----------------------------------------------------------------------

J'ai un soucis avec ce script ,j'aimerai que ma ( sMsg = "Sauvegarde terminée"
MsgBox sMsg, 64, sTitle) soit lancé dés que robocopy finis de backup les données ,
voila je Sais pas si j'ai était claire..
donc si quelqun peut m'aider :)
Merci

Azame

2 réponses

raymix Messages postés 4 Date d'inscription jeudi 10 décembre 2009 Statut Membre Dernière intervention 4 janvier 2010
10 déc. 2009 à 15:35
Bonjour,

Sauf erreur, vbs attend la fin de owsh.exec(sCommand) pour poursuivre. Le doevents n'est peut-être pas nécessaire. Il est de toute façon possible de récupérer la sortie console de robocopy et de l'analyser pour verifier que le backup est fini (en cherchant le mot "Ended", par exemple), voire de récupérer les erreur de copie (recherche de "ERROR"):
Après la ligne set x = owsh.exec(sCommand), on rajoute:

SortieConsole = x.StdOut.ReadAll
if instr(SortieConsole,"Ended") <> 0 then
'ici on met sMsg
end if

ou bien ligne à ligne, pendant l'execution:

do while not x.StdOut.AtEndOfStream
LigneConsole = x.StdOut.ReadLine
if instr(SortieConsole,"Ended") <> 0 then
'sMsg
end if
loop

Ai-je répondu à la question?
0
raymix Messages postés 4 Date d'inscription jeudi 10 décembre 2009 Statut Membre Dernière intervention 4 janvier 2010
10 déc. 2009 à 15:38
Oups,
Dans la deuxième forme il fallait lire instr(LigneConsole,"Ended"), bien sûr!
0
Rejoignez-nous