With the below code I am getting an error "Invalid interface LAN: specified". This code works in Win7, however, does NOT working in windows XP. I suspect it has something to do with the "!adapterName!" conflicting within XP.
I utilize this script to obtain the NIC Name in case it changes in the future some how and would like to keep this scheme. Any ideas how I can continue with such script in an XP environment?
:: Set primary and alternate DNS for IPv4
@ECHO OFF
for /f "tokens=* delims=0" %%a in ("%SITEID%") DO set DROPZERO=%%a
SETLOCAL EnableDelayedExpansion
SET adapterName=
FOR /F "tokens=* delims=:" %%a IN ('IPCONFIG ^| FIND /I "ETHERNET ADAPTER"') DO SET adapterName=%%a
REM Removes "Ethernet adapter" from the front of the adapter name
SET adapterName=!adapterName:~17!
REM Removes the colon from the end of the adapter name
SET adapterName=!adapterName:~0,-1!
echo Setting Static IP Information...
set IP_Addr=10.102.%DROPZERO%.105
set D_Gate=10.102.%DROPZERO%.1
set Sub_Mask=255.255.255.0
netsh interface ip set address "!adapterName!" static %IP_Addr% %Sub_Mask% %D_Gate% 1 > output_net.txt
netsh interface ip set dns name="!adapterName!" static 10.98.1.26 primary >> output_net.txt
netsh interface ip add dns name="!adapterName!" 10.98.1.48 index=2 >> output_net.txt
Here is an improved version of the batch code posted by T-Diddy which works on English and German Windows.
I don't see here a problem on Windows XP on using
But in the
for
loop the commandfindstr
is used instead offind
. And double quotes are used on setting the adapter name to avoid that by mistake a trailing space is appended to the name of the adapter. That could be the important difference.A general note for everybody reading this answer:
Never enter the 4 octets of an IPv4 address with 1 or 2 leading zeros. That could very easily result in being interpreted as octal number which is definitely not expected by anybody.
You don't believe that. Try it out on Linux or Windows for example on running the command
Do you have expected that ping is executed with 192.168.40.16 as written in output?