File Backup

For many of us, backing up our files is a tedious process that is usually forgotten about or ignored, but is usually one of the most invaluable things when we have a problem with our computer. Some of us will use traditional batch files to backup our files onto another 'remote' computer, this script shows you how to create a WSH component to do it for us, for this example we shall use VBScript to create the WSH file.

To do our back up we need to connect to our 'remote' location and then copy some files from our local computer to this new location. A quick look on MSDN reveals the code we require to create the connection to the remote server :

Dim net
Set net = CreateObject("WScript.Network")
net.MapNetworkDrive "I:", "\\backup_server\c$"

All that remains is to copy the files from our computer to a directory on the I drive. A quick search of MSDN again reveals the information that we require to copy the files :

Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "c:\my_data\*.*", "i:\greg_griffiths\"

Instead of using the FSO, we could have used linked directly to the operating system and called the copy command as described here either by running it directly or by calling it via a link to the :

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "copy c:\my_data\*.* i:\greg_griffiths\"


Dim oShell
Set oShell = WScript.CreateObject ("") "command /K copy c:\my_data\*.* i:\greg_griffiths\"

So we have a completed backup script using WSH. The heavily commented complete code is also available for download.