21

I want to have an executable run every time I connect to my wireless network at home. The purpose is to sync a folder on my laptop with my desktop machine.

Is there any way run a program or script when you join a wireless network?

I'm running Windows 7, and I'd also be happy to use a program that takes care of this kind of task.

2 Answers 2

18

I had this exact question, and Darren's answer was on the right track, but didn't get me all the way there. Here's what I ended up doing.

First determine which event you want to use to trigger the task. Run the Event Viewer program and navigate to: Applications and Services Logs > Microsoft > Windows > WLAN-AutoConfig > Operational

In my case, I didn't want my task to run until I was actually connected to a specific WiFi network, so the Event ID I needed was 8001. The quick way to create a task based on this event is to right-click on the event and select "Attach Task To This Event..."

here's a screenshot

In the window that pops up, name your task something clever and add a description so you'll remember what it is later. Go through the wizard, selecting the program you want to run, etc., and when it gets to the last screen, check the box that says "Open the Properties dialog for this task when I click Finish".

At this point, the task will run when the computer successfully connects to any wireless network. To limit it to one particular network, you'll have to modify the task to filter for something unique in the meta data, like the network's SSID. In the properties dialog for the new task, go to the Triggers tab and edit the trigger.

Now, make note of the values for the Basic trigger. You're going to switch to a Custom trigger, and when you do, it'll start blank and you'll need to fill the values in again. After clicking "New Event Filter..." recreate the basic filter by selecting the necessary Event log, Event source, and entering the Event ID.

Note that there's no place to specify meta data from a particular event (such as the SSID of the wireless network). You'll need to edit the raw XML to make this happen, as I discovered in this article.

To figure out which meta data you need to filter in the Event Log, go back to the Event Viewer and click the Details tab for the event. Switch to the XML view. For this particular case, the relevant bit looks something like this:

<EventData>
  ...
  <Data Name="SSID">Your WiFi Network</Data>
  ...
</EventData>

Back on the New Event Filter dialog, switch to the XML tab and check the box next to "Edit query manually".

Referring back to the article linked above, you'll see that the string you need to add will look something like this:

and *[EventData[Data[@Name='SSID']='Your WiFi Network']]

Paste this right before the </Select>

Boom. You're done.


Just a note that might make this easier, rather than editing the XML for the trigger, you can switch to the Conditions tab when bringing up the properties for the task. Here there is an option to 'Start only if the following network connection is available:' and provides a drop down list of networks that you have previously connected to. I suspect this would filter the trigger appropriately as well. Justin

2
  • With Windows 7 I didn't manage to get the trigger working correctly with the "Start only if [..]" dropdown but with the custom trigger and the XML you mentioned it worked. When using the dropdown menu (which wasn't showing the SSID I needed) I always stopped because of this condition.
    – joweiser
    Mar 1, 2013 at 12:05
  • "The network connection being available" doesn't mean the client is connecting or connected to determined network connection, per the OP request.
    – Gaia
    May 5, 2016 at 5:48
7

You can use Windows 7 Task Scheduler for this.

Under Triggers Tab, Begin the task On an event

I don't run Windows 7 on a laptop, but I believe the Event ID can be found in Microsoft-Windows-WLAN-AutoConfig.

Under Conditions Tab, Start Only if the following network connection is available, and specific the Wireless network you want.

Then call the program under Actions.

1
  • "The network connection being available" doesn't mean the client is connecting or connected to determined network connection, per the OP request.
    – Gaia
    May 5, 2016 at 5:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .