If you have a single domain spread over many sites it can be useful to be able to detect where the machine is and then connect it to the local printer or network shares. This is especially useful if you have roaming users who move between offices.
If you have a static environment and can control the naming convention then there is an alternative solution which may work better for you. More Information.
One method that works it to use the default gateway of the machine to detect where the machine is located. You must have different IP address ranges in each site for this to work correctly. Below is an example script with notes so that you can adjust how it for your own environment.
Note: Numbers in the notes correspond with the numbers down the side of the example script.
1. rem Subnets for reference
rem UK subnet: 192.168.22.254
rem US subnet: 192.168.11.254
2. rem Retrieve IP address and dump to a file
3. echo Checking for your location 4. rem Seaching for default gateway in IP dump above
findstr "192.168.22.254" "%userprofile%\ipconfig.txt"
if not errorlevel 1 goto UK
echo Not UK
findstr "192.168.11.254" "%userprofile%\ipconfig.txt"
if not errorlevel 1 goto US
echo not US
rem UK settings
rem US settings
rem Other settings (for VPN etc)
rem more commands
Complete Sample - Ready to Copy and Paste.
Remember to turn off word wrap when working in notepad
Copyright Sembee Ltd. 1998 - 2015.
Reproduction of any content on this web site is prohibited without express written consent. Use of this web site is subject to our terms and conditions.
All trademarks and registered trademarks are property of their respective owners. This site is not endorsed or recommended by any company or organisation mentioned within and is to provide guidance only and as such we cannot be held responsible for any consequences of following the advice given.
Sembee Ltd. is registered in England and Wales at 1 Carnegie Road, Newbury, Berkshire, RG14 5DJ.
Registered company number: 4704428. VAT Number GB 904 5603 43.