Perform functions based on Subnet without temp files

This tip explains how to determine the Subnet and map a drive based on the Subnet without using temp files.

This is an adaptation of Randy Brown's tip Login Script: Perform functions based on Subnet which explained how you can determine the Subnet and map a drive based on the Subnet. I've adapted the tip so that you don't have to use temp files.

 

@echo off REM Note Orignal Credit: creator Randy Brown 09.15.06 Rem Modified by Paul Kochie 10.03.06 Rem I modified Mr. Brown's code to do the same thing without the use of a temp file. cls REM LOGIN.BAT REM Default Login Script REM REM NOTE: When calling other batch files from this login script, there are two important things to keep in mind. REM - always be sure to use 'call' before the batch file name REM - never use 'exit' in the batch file that you are calling REM Failure to keep these things in mind will cause this login script to terminate after calling. REM the other batch file. REM Determine Subnet, do things based on SUBNET REM ALL USERS section is where things go that need to happen for all users regardless of subnet. echo Temporarily removing F drive... echo. net use f: /delete REM Rem where you see tokens=3 you can chage the 3 to 1,2,3 or 4 depending on which octet of the ipaddress you are looing for. for /f "tokens=2 delims=:" %%i in ('ipconfig ^| find /i "IP Address"') ; for /f "tokens=3 delims=." %%j in ('echo %IP%') do set SUBNET=%%j if %SUBNET%==16 goto 16_SUBNET if %SUBNET%==100 goto 100_SUBNET if %SUBNET%==250 goto 250_SUBNET goto ALL_USERS :16_SUBNET net use F: {16_subnet_server}share echo Welcome to the 16 subnet! goto ALL_USERS :100_SUBNET net use F: {100_subnet_server}share echo Welcome to the 100 subnet! goto ALL_USERS :250_SUBNET net use F: {250_subnet_server}share echo Welcome to the 250 subnet! goto ALL_USERS :ALL_USERS REM Use this section to perform functions that pertain to all users goto END :END

Please let us know how useful you find this tip by rating it below! If you have a useful Windows tip, timesaver or workaround to share, submit it to our tip contest and you could win a prize! 

This was first published in October 2006

Dig deeper on Windows File Management

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close