convert user input as variable in batch file

August 30, 2012 at 02:35:27
Specs: Windows XP
dear gurus,
I am newbe in batch file scripting, looking forward for your help in this regards from all of you, (I will try my best to explain my problem)

I have a batch file to change IP, MASK, GATEWAY and DNS of my machine, but I want to make it little intelligent, if I select 1 then automatically wire interface name will be use in next command to set IP etc... or if I select 2 then WiFi interface name will be use in command. my existing script is as follows.

@echo off

set wifi_name=WiFi
set wire_name=WIRELAN
set wire_ip=192.168.0.117
set wire_mask=255.255.252.0
set wire_gw=192.168.0.130
set wifi_ip=192.168.105.117
set wifi_mask=255.255.255.0
set wifi_gw=192.168.105.130
set dns1=4.2.2.1
set dns2=4.2.2.2
set dns3=4.2.2.3
set dns4=4.2.2.4
set "wire_ins=PCI\VEN_10EC*"
set "wifi_ins=USB\VID_0BDA*"

echo.
echo Select Location You Want To Connect
echo.
echo [1] Office WIRE Network
echo [2] Office WIFI Network
echo [3] Exit
echo.
:network
@echo off
SET /P E=[1, 2, 3]?
for %%? in (1) do if /I "%E%"=="%%?" goto wire
for %%? in (2) do if /I "%E%"=="%%?" goto wifi
for %%? in (3) do if /I "%E%"=="%%?" goto end

:wire
@echo off
echo "Enabling Wire Interface and Disabling WiFi"
echo.
devcon disable "%wifi_ins%"
echo.
devcon enable "%wire_ins%"
echo.
netsh int ip set address "%wifi_name%" source = dhcp
echo.
netsh int ip set dns "%wifi_name%" dhcp
echo.
echo Setting IP, MASK, and Gateway
netsh interface ip set address "%wire_name%" static %wire_ip% %wire_mask% %wire_gw% 1
echo Setting DNS Primary
netsh interface ip set dns "%Wire_name%" static %dns1%
echo Setting DNS Secondary
netsh interface ip add dns "%wire_name%" %dns2% index=2

goto end

:wifi
@echo off
echo "Enabling WiFi Interface and Disabling Wire"
echo.
devcon disable "%wire_ins%"
echo.
devcon enable "%wifi_ins%"
echo.
netsh int ip set address "%wire_name%" source = dhcp
echo.
netsh int ip set dns "%wire_name%" dhcp
echo.
echo Setting IP, MASK, and Gateway
netsh interface ip set address "%wifi_name%" static %wire_ip% %wire_mask% %wire_gw% 1
echo Setting DNS Primary
netsh interface ip set dns "%Wifi_name%" static %dns1%
echo Setting DNS Secondary
netsh interface ip add dns "%wifi_name%" %dns2% index=2

goto end

:end

----------- End of Script ----------------


See More: convert user input as variable in batch file

Report •


#1
August 30, 2012 at 05:43:23
:: ===== script starts here ===============
::
:: rric.bat 2012-08-30 19:37:43.93
@echo off & setLocal enableDELAYedeXpansioN

choice /c123 1 LAN 2 wifi 3 quit
call :!ERRORLEVEL!
goto :eof

:1
echo LAN
goto :eof
:2
echo wifi
goto :eof
:3
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •
Related Solutions


Ask Question