Roberto Alves

Scripting and server based computing

.VBS Copying files to many locations

This is a very simple script that copies a folder from a specific path to all servers listed on servers.txt file.

There is a file called progress.htm that runs an activeX control that shows a progress bar, that increases when the copy is done on each server.

On Error Resume Next

source_server = “machine_name”
source = “c$InstallCPS45HF”

Dim server()

Set objFSO = CreateObject(“Scripting.FileSystemObject”)


Set MyFolder = objfso.GetFolder(“./”)

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootcimv2″)
Set colItems = objWMIService.ExecQuery(“Select * From Win32_DesktopMonitor”)
For Each objItem in colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next

Set objExplorer = CreateObject(“InternetExplorer.Application”)
objExplorer.Navigate “file:///” & Myfolder & “progress.htm”
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 450
objExplorer.Height = 90
objExplorer.Left = (intHorizontal – 450) / 2
objExplorer.Top = (intVertical – 90) / 2
objExplorer.Visible = 1

Do While (objExplorer.Busy)
Wscript.Sleep 200
Loop

Set objFile = objFSO.OpenTextFile(Myfolder & “servers.txt”, 1)

x = 1
Do Until objFile.AtEndOfStream
Redim Preserve server(x)
server(x) = objFile.ReadLine
x = x + 1
Loop

objFile.Close

intIncrement = 100/ubound(server)

for x = 1 to UBound(server)
‘msgbox “\” & trim(source_server) & source & “\” & trim(server(x)) & “c$Install”
objFSO.CopyFolder “\” & trim(source_server) & source, “\” & trim(server(x)) & trim(source), True
objExplorer.Document.Body.All.ProgressBar1.Value = objExplorer.Document.Body.All.ProgressBar1.Value + intIncrement
Next

objExplorer.Quit
msgbox “Done!”

Progress.htm

<html>
<head>
<title>Please wait</title>
</head>
<body bgcolor=”buttonface”>
<p>
<object classid=”clsid:35053A22-8589-11D1-B16A-00C0F0283628″ id=”ProgressBar1″ height=”20″ width=”400″>
<param name=”Min” value=”0″>
<param name=”Max” value=”100″>
<param name=”Orientation” value=”0″>
<param name=”Scrolling” value=”1″>
</object>
</p>
</body>
</html>

Category: Scripts
Tag: , ,

Your email address will not be published. Required fields are marked *

*