Windows: Connect Network Drive and Copy Remote Files at Login

As the title suggests, this entry will show you how to connect a network map on your Windows machine, and copy folders from that network storage during login.

The situation: I have a NAS on the local network, but just in case, I would like to backup files from the NAS to my local desktop.

Prerequisites:

  • A network drive that can be mounted. For me, I have a local NAS that hosts a Media folder with Sambda (SMB) on address 192.168.1.100.
  • Windows 10 with a network map already created to this network drive. For this example, my network drive will be \\192.168.1.100\Media (N:).

———————————

Step 1. Write the batch script.
This batch script will mount the network drive and use robocopy to copy any new or updated time-stamped files to the C: drive destination.

@echo off
cd\
net use N: \\192.168.1.100\Media
robocopy N:\Pictures C:\Users\Dave\Pictures /FFT /Z /XA:SH /XD *. /W:5 /E

You can save the file where you like, but in my case, I use C:\Users\Dave\bin\picture_sync.bat.

I should also note that robocopy is a very robust tool, so it could be worth your time to investigate those options that work best for you.

Step 2. Wrap the batch script into a VBS script.

I wrote the following script in a file called picture_sync_wrapper.vbs:

Set shell = CreateObject(“WScript.Shell”)
shell.CurrentDirectory = “C:\Users\Dave\bin”
shell.Run “picture_sync.bat”,0,True

Q. Why write a VBS script?
A. To suppress the script when running during login. If you set the batch script to run, you will see a command window pop-up. While this window will close when finished, I like having it run to where I can forget about it. There are other options, like converting the batch script to an exe file, but I find this the easiest.

Step 3. Drop the VBS script in your user’s startup directory

In my case this will be C:\Users\Dave\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\. If you do not like all that digging down, you can also “Win Key + r ” and enter “shell:startup” and a new window will take you there. Drop your vbs script, in my case picture_sync_wrapper.vbs, here.

———————————

That’s it! Now when you login, any new files on the network drive will be copied over to your local disk. It is always nice to have a backup of a backup ๐Ÿ™‚

Leave a Reply

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

*