Enumerating the If... Then: Scripts

Saturday, March 24, 2007

VBScript: ProxyShutterOffer

Tested.
In use at work.


Download VBS


This script will ping a server name (set within the script).

If it's reachable, the script assumes you're attached to the network, and turns the IE proxy on (via a registry edit).

If it's unreachable or the Name doesn't resolve (or one of many statuscodes that aren't a success), the script assumes you're not on the network, and turns the IE proxy off.

Usage:
Used on laptops at work so that user's can access the internet when they are connected to their home network.
Edit the script and set the strWorkServer string (just replace the server name I-Am-A-DC).
Place a shortcut to the script in the user's startup folder, or you can go to the LaunchIE function (last portion of this script) and remove the comment-mark (the apostrophe) from the beginning of the line to automatically launch IE. Place a shortcut to this script on the user's desktop, and change the icon to iexplorer.exe's.

Reasoning:
There is no simple way to tell if a user has authenticated to the network or not. When a user is using cached credentials, the logonserver environmental variable continues to be set to the Domain Controller, even if the user hasn't, technically, authenticated to it.
Another method would be to find the computer's IP address and check the subnet versus a subnet on your network. I figure it's much less likely that the user will have another computer with the name of a DC (ex: DC-B1-WorkyCorp) on their network then they'll be using the same subnet.