HowTo: Auto synchronise files upon network connection (Windows)


Working away from the office means working without the safety net of backup infrastructure. What would be nice is for file synchronisation to happen automatically the moment you reconnect — no remembered steps, no manual copy-paste, no crossed fingers.
Holding back the urge to write something bespoke, the solution here uses three tools already present on most Windows machines: Git, RoboCopy, and Task Scheduler.
Note — modern alternatives exist. This post was written in 2014, before cloud sync tools such as OneDrive, Syncthing, and Resilio Sync became ubiquitous. If you are on a standard corporate laptop with internet access, those tools will serve you better. However, the underlying pattern — event-triggered file sync via Task Scheduler responding to a network connection event — remains entirely valid for air-gapped environments, restricted networks, or scenarios where cloud sync is not permitted.
Key Takeaways
- Windows raises event ID 10000 under
Microsoft-Windows-NetworkProfile/Operationaleach time a network profile connects — this is your trigger. - Task Scheduler can fire any script or executable in response to that event, filtered to a specific named network.
- RoboCopy with
/MIRis the right tool for a straight folder-to-folder mirror. - Git is the right tool when you want version history alongside the sync.
- The two approaches are complementary — you can run both from a single batch file.
What problem does this solve?
Laptop disks fail. Files get accidentally deleted. Travelling is hard on hardware. The goal is a solution that:
- Mirrors data to a network location that has its own backups.
- Triggers automatically on network connection — physical or VPN.
- Requires no user action after initial setup.
USB keys are not an adequate substitute. They get lost, they are not versioned, and they require the user to remember to plug them in.
How does the trigger work?
Windows raises event ID 10000 in the Microsoft-Windows-NetworkProfile/Operational log every time a network profile connects. Task Scheduler can subscribe to this event and fire a task in response.
The task can additionally be constrained to a specific named network connection, so it only runs when you are on the right network — not every time you connect to any Wi-Fi.
Setting up the Task Scheduler trigger
First, create a basic task to verify the trigger fires correctly. Use a simple command prompt as the action — you can replace it with your sync script once everything is confirmed working.
- Open Task Scheduler (Start Menu → type Task).
- Right-click Task Scheduler Library and select Create Basic Task.
- Work through the wizard:
- Give the task a name and click Next.
- Set the trigger to "When a specific Event is Logged" and click Next.
- Set Log to
Microsoft-Windows-NetworkProfile/Operational. - Set Source to
Network Profile. - Set Event ID to
10000and click Next. - Set the action to "Start a program".
- Enter
cmdin the Program/Script field and click Next. - Tick "Open the Properties dialog for this task when I click Finish" and click Finish.
- In the Properties dialog, switch to the Conditions tab.
- Under the network section, select the specific network name you want to trigger on.
Disconnect from that network, reconnect, and a command prompt window should appear. Once confirmed, replace cmd with your sync script.
Option A — Synchronise with RoboCopy
RoboCopy is the straightforward choice for mirroring a folder to a network share. Change the task action to call RoboCopy directly:
robocopy \\SourceServer\Share \\DestinationServer\Share /MIR /ZB /XA:H /W:5What each flag does
| Flag | Effect |
|---|---|
/MIR | Mirrors the source to the destination — files deleted locally will also be deleted at the destination. |
/ZB | Enables restartable mode so large file transfers survive interruptions; falls back to backup mode if needed. |
/XA:H | Excludes hidden files, which are typically system files of no interest. |
/W:5 | Reduces the retry wait time from 30 seconds to 5 seconds on failure. |
Note the /MIR flag: deletions are mirrored. If you delete a file locally, it will be removed from the destination on the next sync. This is usually the desired behaviour for a mirror, but worth being aware of.
Option B — Synchronise with Git
If you want version history alongside your sync — the ability to roll back to any previous state — Git is the better tool. The sync becomes a git push rather than a file copy.
Initial setup
- Initialise a bare repository in your network share folder (for example,
H:\Projects). Start with an empty folder for simplicity. - Clone that bare repository to your local drive (for example,
C:\_Work). - Add your existing files to the local repository and commit them.
You can now commit locally as often as you like, view history, and restore any previous version — all without needing network access.
Automating the push on network connection
Create a batch file containing the following:
@echo off
c:
cd \_Work
git add -A && git commit -am "AutoSync commit"
git pushChange the scheduled task to execute this batch file instead of cmd. Every time you connect to the network, the task will stage all changes, commit them, and push to the network share — full change history included.
Choosing between RoboCopy and Git
Use RoboCopy when:
- You are syncing files that do not benefit from version history (media, large binaries, build artefacts).
- You need the destination to be a plain folder accessible without Git tooling.
Use Git when:
- You want to track changes over time and be able to roll back.
- The files are text-based (code, documents, configuration).
- You already use Git in your workflow.
There is nothing stopping you from running both from a single batch file — RoboCopy for one folder tree, Git push for another.
Solution Architect with 30 years in cloud infrastructure, security, identity, and .NET engineering.