Can someone help me with this one? I have a batch file, where I am trying to connect a couple network drives based on my current internal IP address. Problem is, it is outputting the following:
Home 192.168.2.99
Basement
Where it should be just outputting:
Home 192.168.2.99
Here’s the code:
@echo off
@for /F "tokens=2 delims=:" %%i in ('"ipconfig | findstr IP | findstr 192."') do SET LOCAL_IP=%%i
@if ("%LOCAL_IP%" == "192.168.2.99") Call ConnectHome else (Call ConnectBasement)
:ConnectHome
@echo Home %LOCAL_IP%
:ConnectBasement
@echo Basement
@REM net use R: \\192.168.2.98\Storage
@REM net use S: \\192.168.2.98\MyStuff
@REM net use T: \\192.168.2.98\Server
I’ve also tried replacing the IF statement with:
@if ("%LOCAL_IP%" == "192.168.2.99") goto ConnectHome else (goto ConnectBasement)
and:
@if ("%LOCAL_IP%" == "192.168.2.99") goto :ConnectHome else (goto :ConnectBasement)
and the results are always the same…
OS is Windows 7 Pro
Callis intended to call a different batch file from the one you’re currently in (see here). If it’s passed a label, it will execute from that label, but it’ll execute to the end of the file, so it won’t stop when it hits the :ConnectBasement line.What you probably need is to add a label
:ENDat the bottom of the file, andGoto :ENDjust before your :ConnectBasement line. For consistency I’d probably suggest usingGotoinstead ofCallthroughout. (You can also useGoto :EOFwithout defining a label, if you wish.)(Or, learn PowerShell and use its functioning capability to implement this more cleanly ;-))