Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to create a script to do various things when the network connection changes. For example, if the machine connects to my office network I might desire it to:

  • mute itself
  • change its DNS
  • change its proxy settings
  • change default printer

Then, when the machine is off the office network it might revert some of those.

Presumably the "active network" would be based on IP address/gateway range or WIFI network name, etc.

Do you have any recommended tools for accomplishing this? I can see something like this being applicable to many IT pros so I'm sure there are some good tips out there.

Note that this is desired to function when the network changes--not just when the user logs on/off.

share|improve this question
Would this be for Windows then? If so, which version? – squillman Jun 15 '09 at 18:25
Ah, yes, WindowsXP. Other flavors are welcome, too, but we're predominately winxp for now. – Michael Haren Jun 15 '09 at 18:26
Not that it helps, but Windows 7 has some nice features for better network location profiling. – MathewC Jun 15 '09 at 18:45
Please post references--that'll help me eventually and perhaps others right now. – Michael Haren Jun 15 '09 at 18:46

5 Answers

up vote 3 down vote accepted

The "Network Location Awareness" service (http://msdn.microsoft.com/en-us/library/ms739931(VS.85).aspx) in Windows XP (and 2000? I don't recall...) and up will enable this functionality, but I haven't found where anybody has written an application to take advantage of it. I'd love to code something myself, but I don't have enough spare cycles to even begin to think about it.

This wouldn't be a simple little VBScript thing, but it wouldn't be that much coding either. Maybe somebody could pick up the idea and run with it. There's even sample code at http://www.microsoft.com/downloads/details.aspx?familyid=ef8a6228-f11d-4ba0-b73e-dd8dc7dd11e8&displaylang=en.

There have been numerous times I've wanted this functionality, and I'd think there are more than a few people who would like to see it.

share|improve this answer
I, sir, will heed your call...eventually. I might dabble in this very soon as my long overdue contribution to the open source community. – Michael Haren Jun 15 '09 at 18:33
Seriously, look me up if you're going to code something. If you'll license your code with GPL, MPL, or some other reasonably open license (and the code actually works) I'll throw some money your way. – Evan Anderson Jun 15 '09 at 19:10
I don't know if it's improved any in recent years (Post XP SP1 at any rate) but I burned a lot of time some years ago trying to build code that used NLA and I came to the conclusion that NLA was pretty much useless because it could take minutes to fire an event following a change (network connect\disconnect\whatever). If I recall correctly the IPHelper API's NotifyRouteChange was much faster (fractions of a second) but obviously more limited in what would trigger it. – Helvick Jun 30 '09 at 6:27

I've had some success with Net Profiles before.

share|improve this answer
This seems to work quite well. I need to figure out how to do individual things like mute the machine but it looks like I could tie a cmdlet into this pretty easily. It switches profiles based on WIFI name which is enough for me. Thanks! – Michael Haren Jun 15 '09 at 20:29

You could create a batch file that reads the results of an ipconfig command, and have it run every 5 seconds or so...

share|improve this answer
Eww... ick. There is already a service in the OS to handle this. Somebody just needs to write the code. I'd be more than willing to contribute some money to development of an open source utility to utilize this functionality. – Evan Anderson Jun 15 '09 at 18:31
While I appreciate the gets-things-done mentality behind this approach, I'll hold out for something a little more elegant – Michael Haren Jun 15 '09 at 18:34

Using .net framework version 2 it is possible to use the System.Net.NetworkInformation namespace. From this you can determine:

network availability: NetworkAvailabilityChangedEventHandler() network address changes: NetworkAddressChangedEventHandler() ipaddress: IPAddressInformation

and so on.

How much of this is available through powershell I don't know because I don't use it. But I have written a very simple vb.net tray application that just monitors network availability and connects to a network share when the network is available. If you're interested in the bare-bones of the code then let me know.

share|improve this answer
I'd be interested by the vb.net tray application you developed. Could u please share the source code with the community ? Thx – crousti Oct 29 '10 at 10:16

This is kind of a sideways and partial answer (and not even documented because I can't seem to find the original article), but I'm fairly sure Windows 7 has a property sheet on the printer object allowing you to change defaults depending on subnet.

I'd love to see features addressing the rest of your list, as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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