Perform functions based on Subnet without 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

Requires Free Membership to View

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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.