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.
You can do it using Task Scheduler:
Just in case, there are also events for computer "Suspend" and "Resume" available there. I, for example, use them to stop and restart Hamachi on these events, since otherwise it seems to have problems on my machine.
For computer "Suspend" You can use Log "Microsoft-Windows-Kernel-Power/Thermal-Operational", Source "Kernel-Power" and the Event ID is 42.
For computer "Resume" You can use Log "System", Source "Power-Troubleshooter" and the Event ID is 1.
For user login/logoff, I do not know events under Task Scheduler (but I believe they are available there too), but You can configure it instead here:
You can do similar stuff for computer "Startup" and "Shutdown" events under "Computer Configuration" folder in the same window. The Startup script runs under System account before the user logs on.
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.
I've had some success with Net Profiles before.
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.
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.
You could create a batch file that reads the results of an ipconfig command, and have it run every 5 seconds or so...