I'm trying to make a batch file that will check your computer's name, and then it will set your IP address to the corresponding IP address for that computer.
I have a variable called IPAddress that stores the new IP address. Then I have an IF statement to check the computer name and assign the new IP address. My problem is that inside the IF statement, when I set the IPAddress variable to the new IP I want, it doesn't stick. When I try echoing the IPAddress variable right after I set it, it's still the original state.
Here's my code:
@echo off
SET IPAddress=192.168.1.1
IF %computername%==TEST (
ECHO "TEST" computer
SET IPAddress=192.168.1.50
ECHO New IP Address: %IPAddress%
) ELSE IF %computername%==BRIDGE (
ECHO "BRIDGE" Computer
SET IPAddress=192.168.1.25
ECHO New IP Address: %IPAddress%
)
pause
I am on the "BRIDGE" computer and I get this output:
"BRIDGE" Computer
New IP Address: 192.168.1.1
Press any key to continue . . .
I can't understand why the SET statement inside the IF statement doesn't seem to be working.
Any ideas?
Thanks in advance!