I'm after a way of running a script (on Windows) when a network connection is established.

Background: I'm looking at the potential of having a low powered computer that sits in the boot of my car storing a lot of audio files, running Subsonic and using the Android app as a "jukebox" controller that plays the music through the soundcard of the computer to an input on the stereo, or broadcasts it over a local radio channel to my car stereo. When I arrive home, it will connect to my home wireless, run a sync with my media server to download any music it hasn't got on it, then hibernate.

My question then, is how can I run the sync when I connect to the network? My current idea is to ping the gateway every 30 minutes or so, and if the gateway is pingable, run the sync and hibernate, or if not ping 30 minutes later.

I would prefer some Windows-based trickery such as batch-based files or PowerShell, but if the OS will run Subsonic then I may consider that as well.

I could have a lot of CD's in my car...but that's effort to remeber to do - I'm ovbiously not a fan of the easy life.


Use the windows task scheduler. From the task scheduler (Win7 Control Panel, administrative tools), create a new task to specify your sync batch file. On the conditions tab, there is a network option. Check the

"Start only if the following network connetion is available"

and also any other conditions in triggers etc, to limit the sync to happen per your needs. enter image description here


There is a more direct way: use the NetworkConnected event (ID 10000) as trigger: Task trigger configuration

This way the task runs immediately every time the network is connected.

You may also want to uncheck "Start the task only if the computer is on AC power" on the Conditions tab and select "Run whether user is logged on or not" on the General tab.

Thanks to jdh for the idea of using Task Scheduler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.