Mapping drives based on location

Published 17 September 09 07:21 AM | rodtrent

I concocted this batch file script a couple weeks ago to determine where a client was accessing the network from and then mapping shares accordingly.  In this instance, folks were logging in through either Citrix of the local LAN.  If they were logging on by way of the LAN, the DFS shares needed to be mapped.  If logging on through Citrix, they needed to log on directly to the shares, instead of the DFS replicas.

I did this based on the IP address of the Gateway obtained through the connection.  As you can see the Gateway changed based on the location, so it was easy to determine where they client was logging in from.  There’s also another section in the script so that a VPN or “other” connection can be added to the logic, too.

To use the script just spot the IP Gateway address fields (XXX for one Gateway, YYY for the other) and modify based on the IP Gateway addresses assigned in your organization.

 

rem Subnets for reference
rem Citrix Gateway: XXX.XXX.XXX.XXX
rem Server Gateway: YYY.YYY.YYY.YYY
rem Grab IP address and dump to a file

ipconfig >"%userprofile%\ipconfig.txt"

echo Checking for your location

rem Seaching for default gateway in IP dump above
findstr "XXX.XXX.XXX.XXX" "%userprofile%\ipconfig.txt"
if not errorlevel 1 goto Citrix

echo Not Citrix
goto next

:next
findstr "YYY.YYY.YYY.YYY" "%userprofile%\ipconfig.txt"
if not errorlevel 1 goto Server

echo not Server
goto other

:Citrix

net use G: \\server\share
net use P: \\server\share
net use Z: \\server\share
net time \\timeserver /set /y

goto :next

:Server

net use G: \\DFS_ROOT\share
Net use P: \\DFS_ROOT\share
net use Z: \\DFS_ROOT\share
net time \\timeserver /set /y

goto :next

:other
rem Other settings (for VPN etc)
goto :next

:next

rem more commands

:end

Filed under: ,

Comments

No Comments

This Blog

News

    Ni Hao! Wo shi Rod.



    The Bruce Campbell Fan Store



    Proud member of the myITforum Network



Community

Things I've done

myITforum.com

Things I do

Blog Roll

Syndication