Tuesday, April 14, 2009

Prompt for Remote File Copy

Recently we needed to push some files to over 80 remote laptops. Being that they where laptops of course not all of them are on the network at one time (strange...). That being a file with the list of laptops wasn't really an option since the users would be brining in their laptops at unknown times. Being slightly lazy I didn't feel like manually copy the folders each time and came up with this script to help simplify the process so that with just a couple of keystrokes per laptop the files would be copied.

Note: depending on the folder size being copied it may take some time for the Copy Completed box to popup and will appear to be doing nothing while copying.

Dim FSO
Dim fREM, fLOC, cREM

Set FSO =
Wscript.CreateObject("Scripting.FileSystemObject")

cREM = InputBox("Enter the machine name", "Remote Name", "Laptop")

If cREM = False Then
msgbox "You pressed cancel"
Else
fLOC = "C:\Folder\Location"
fREM = "\\" & cREM & "\C$\Location"
msgbox "Copying to " & fREM
FSO.CopyFolder fLOC , fREM, True
msgbox "Copy completed"
End If




This can then be done without any user prompting to call a .bat file (or any other executable type file)

Dim FSO
Dim fREM, fLOC, cREM

Set FSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
comp=oShell.ExpandEnvironmentStrings("%ComputerName%")

fLOC = "C:\Folder\Location"
fREM = "\\" & comp & "\C$\Location"
msgbox "Copying to " & comp
FSO.CopyFolder fLOC , fREM, True

oShell.Run ("C:\LocationofBatchFile.bat")

No comments:

Post a Comment