Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript that waits command Finish

Status
Not open for further replies.

hadesfromhell

Technical User
Mar 2, 2009
3
BR
Hello there,

I made a backup script that Zips some files, and copy them to a remote location. The Script calls a zip program command line, and process the next line ...

I need that the script waits the External command finishes to go on ...

I´m having problems with the script running the next lines without finishing Zip the files ...

Code:
WshShell.Run ("J:\Filzip\Filzip.exe -a -f J:\"& WshNetwork.UserName&"\"& WshNetwork.UserName & ".zip " & Chr(34) & sUserProfile & "\Local Settings\Application Data\Microsoft\Outlook\*.pst" & Chr(34),1)
Does anyone have any idea of how make this script know when to go on ?

 
Code:
WshShell.Run "<your command>"[red],, true[/red]

The section between the commas is used to tell the method the window style (leave blank for default), the section at the end tells it to wait until the command is complete.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 

Thanks, that worked ...

My mistake ... I was using "1" instead of "true", and wrongly ...

As I saw a lot of people interested on a PST backup script, when I finish mine, i´ll post the full code ...

Thanks again
 
You can use 1 instead of true, I use true by personal preference.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Well,

Here follows my script to backup All Outlook PST´s.
Of course it can be improved. And I hope for most, it can be a good headstart.

The destination is a Mapped drive under letter "J".
With this script you will need a zip program, and here I´m using a good freeware called filzip.
All you have to do is install filzip on your machine, and copy c:\program files\filzip to J:\filzip.

Code:
Option Explicit
Dim WshShell
Dim objFSO
Dim WshNetwork
Dim intAnswer
Dim sUserProfile
Dim i
Dim oDrives
Dim oFile
Dim oFiles
Dim oFolder
Dim sPSTPath
Dim sPSTFile
Dim sZipStr
Dim sFilesFound
Dim sQuerysizeloops
sFilesFound=0
sQuerysizeloops=0

Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
sUserProfile = WshShell.ExpandEnvironmentStrings("%UserProfile%")
sPSTPath = sUserProfile & "\Local Settings\Application Data\Microsoft\Outlook\"

Set oFolder = objFSO.GetFolder(sPSTPath)
Set oFiles = oFolder.Files

intAnswer = Msgbox("Deseja fazer o backup do seu e-mail ?",vbYesNo,"Backup")
If intAnswer = vbYes Then
	Set intAnswer=Nothing
	intAnswer = Msgbox("Se seu Outlook estiver aberto, Feche-o AGORA ou ele será fechado. Deseja Prosseguir? ",vbYesNo,"Fechamento do Outlook")
	If intAnswer = vbYes Then
		WshShell.Run "taskkill /F /im Outlook.exe"
		If not objFSO.FolderExists("J:\"& WshNetwork.UserName)then
			objFSO.CreateFolder("J:\"& WshNetwork.UserName)
		End If
		For Each oFile in oFiles
			'On Error Resume Next
			If oFile.Type = "Office Data File" Then
				sFilesFound = sFilesFound + 1
				sZipStr = "J:\Filzip\Filzip.exe -a -f J:\"&WshNetwork.UserName&"\"&WshNetwork.UserName&"_"&Year(Date())&"_"&Month(Date())&"_"&Day(Date())&".zip " & Chr(34) & sPSTPath & oFile.Name & Chr(34)
				'### Descomente a linha abaixo para exibir um warning ao usuário caso o PST dele for maior que 3Gb
				'Querysize (oFile.Name)
				RegFilzip ()
				WshShell.Run sZipStr,,True	
			End If
		Next
	Else 
		Fim
	End If
Else 
	Fim
End If

Set oFolder = objFSO.GetFolder ("J:\"&WshNetwork.UserName)
Set oFiles = oFolder.Files

For Each oFile In oFiles 
	If Not oFile.Name = (WshNetwork.UserName&"_"&Year(Date())&"_"&Month(Date())&"_"&Day(Date())&".zip") Then
		oFile.Delete
	End If 
Next

Sub RegFilzip ()
'#### Rotina para registrar as chaves de registro do Filzip e não exibir nada ao usuário. 
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.ace","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.arc","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.arj","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.bh","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.cab","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.fea","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.fzs","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.gz","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.jar","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.lha","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.pak","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.rar","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.tar","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.uue","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.xxe","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.z","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\.zip","1","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\Associate","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\FileAssociation\Dialog","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\Settings\Language-Ini","J:\Filzip\languages\PortugueseBR.ini","REG_SZ"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\Settings\optOverwrite","1","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\Settings\optUpdate","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\Settings\optZipDirs","0","REG_DWORD"
	WshShell.RegWrite "HKCU\Software\Filzip\Config\Settings\RegDialog","0","REG_DWORD"
End Sub

Sub Querysize (sPSTFile)
	For Each oFile in oFiles
		If oFile.Name= sPSTFile Then
			If oFile.Size > 3221225472 Then
				If sQuerysizeloops = 0 Then
					sQuerysizeloops = sQuerysizeloops+1
					MsgBox "Seu PST é maior que 3GB, é necessário fazer uma limpeza para evitar a perda de arquivos.",48,"Tamanho Crítico"
				End If
			End If 
		End If 
	Next
End Sub

Sub Fim
	Msgbox "Backup Cancelado",,"Sair"
	Set WshShell=nothing
	Set objFSO=nothing
	Set WshNetwork=nothing
	Set intAnswer=nothing
	Set sUserProfile=nothing
	Set i=nothing
	Set oDrives=Nothing
	Set oFile=Nothing
	Set oFiles=Nothing
	Set oFolder=Nothing
	Set sPSTPath=Nothing
	Set sPSTFile=Nothing
	Set sZipStr=Nothing
	Set sFilesFound=Nothing
	Wscript.quit
End Sub

'WScript.Echo "Foram backupeados " & sFilesFound & " Arquivos"
WScript.quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top