Jump to content

Set Ip-Adress in Runonce.cmd


tron

Recommended Posts

Hi guys,

i try to setup my Runonce.cmd like FTP Installation Thread. But i have to setup my IP-Adress first. I dont have a DHCP Server so i have to set this static. But my friends also use this Installation. So i cant setup my network 192.168.122.x. I have to ask for it in ipadress.bat:

Here is the code:

@echo off 
echo Ipadresse festlegen
echo per DHCP Server:
set /p ip1=(j/n):
if /i %ip1%==j netsh interface ip set address "LAN-Verbindung" dhcp
pause
echo Static settings:
set /p ip2=(j/n):
if /i %ip2%==j netsh interface ip set address "LAN-Verbindung" static
exit

DHCP works fine, but how could i set Variables for static settings? Store them in txt file?!

Hope you could help me.

Thx tron

Link to comment
Share on other sites


I think i recognize that ip, Starband ? I'm not sure what you're trying to do but I import a reg file and mine is setup. Check "ProxyServer" under this key

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]

I save and import the whole key. But mine is a workstation on a LAN so not sure that would help you if you're directly connected.

Link to comment
Share on other sites

There's many ways around this problem

1) straight import registry file (probably will fail/have issues in many cases depending on hardware and what not)

2) vbscript, using the Win32_NetworkAdapterConfiguration WMI class (I just love WMI, but do we always have to resort to that for every single small thing?)

3) netsh command line utility, for static IP (which is the one I'd use personally):

netsh interface ip set address "Local Area Connection" static ipaddr subnetmask gateway metric

ie:

netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 1

of course you have to change numbers to match whatever your case might be. There probably are more ways to this as well.

Link to comment
Share on other sites

Thanks for the answers.

crahak netsh is the thing i want. But IP Adress Netmask and Gateway i couldnt set static. In the script there have to be a prompt, where you could type in IP, Netmask and Gateway in. Like in linux...

Then maybe stored in a .txt file and inserted in netsh...

I dont know much about vbscript so i dont know what i have to do with the WMI...

Greetz tron

Link to comment
Share on other sites

Configure your PC for static IP then run this to dump your settings to a txt file.

netsh -c interface dump > c:\location.txt

Copy location.txt to your unattended cd & run this in your batch to set it static.

netsh -f c:\location.txt

Or you could use something like this:

set STATIC_IP=192.168.1.105
set SUBNET=255.255.255.0
set GATEWAY=192.168.1.1

netsh int ip add name="Local Area Connection" static %STATIC_IP% %SUBNET% %GATEWAY% 1

Info from:

http://www.petri.co.il/configure_tcp_ip_from_cmd.htm

hope that helps....

Link to comment
Share on other sites

Hello edg21,

set STATIC_IP=192.168.1.105 <-- User have to insert this information on command prompt
set SUBNET=255.255.255.0 <-- User have to insert this information on command prompt
set GATEWAY=192.168.1.1 <-- User have to insert this information on command prompt

netsh int ip add name="Local Area Connection" static %STATIC_IP% %SUBNET% %GATEWAY% 1

^^ This is very good, but i want to call this file on Runonce.cmd to set the Networksettings before running your ftp.cmd. The thing is that my friends also want to use this CD. His network is different, but to call your ftp.cmd he has to input his IP, Mask and Gateway. So i couldnt set these Options static. My idea was to have a prompt like in linux where he could insert his Networksettings. He also has no DHCP. We need this to have in the next step an internet connection to start your ftp.cmd file.

Hope you understand what i mean.

Thx & Greetz tron

Link to comment
Share on other sites

^^ This is very good, but i want to call this file on Runonce.cmd to set the Networksettings before running your ftp.cmd. The thing is that my friends also want to use this CD. His network is different, but to call your ftp.cmd he has to input his IP, Mask and Gateway. So i couldnt set these Options static. My idea was to have a prompt like in linux where he could insert his Networksettings. He also has no DHCP. We need this to have in the next step an internet connection to start your ftp.cmd file.

Somethin kinda like this?

:NW_CHOOSE
ECHO.
ECHO 1. Set static IP
ECHO 2. Use DHCP
SET /P NW_CONF=[Do you want to specify a static IP or use DHCP? (Select 1 or 2)]
IF /I "%NW_CONF%" == "1" GOTO NW_SET_DHCP
IF /I "%NW_CONF%" == "2" GOTO NW_INPUT

:NW_INPUT
SET /P STATIC_IP=[IP:]
SET /P SUBNET=[Subnet Mask:]
SET /P GATEWAY=[Default Gateway:]
ECHO.
ECHO You specified:
ECHO IP Address: %WEB_ADDY%
ECHO Subnet Mask: %WEB_ADDY%
ECHO Default Gateway: %WEB_ADDY%
:NW_CONFIRM
ECHO.
SET /P NW_CONF=[Is this correct? Y/N:]
IF /I "%NW_CONF%" == "Y" GOTO NW_SET
IF /I "%NW_CONF%" == "N" GOTO NW_INPUT
GOTO NW_CONFIRM

:NW_SET_STATIC
netsh int ip add name="Local Area Connection" static %STATIC_IP% %SUBNET% %GATEWAY% 1
GOTO END

:NW_SET_DHCP
netsh int ip set add "Local Area Connection" dhcp
GOTO END

:END

Link to comment
Share on other sites

edg21 you are the man.... :)

really really good. Thats what ive searching for...

Ive modified the script a bit and it is still in Progress.

@echo off
:NW_CHOOSE
ECHO.
ECHO 1. per DHCP
ECHO 2. Statische IP-Adresse
SET /P NW_CONF=[Do you want to use DHCP or specify a static IP? (Select 1 or 2)]
IF /I "%NW_CONF%" == "1" GOTO NW_SET_DHCP
IF /I "%NW_CONF%" == "2" GOTO NW_INPUT

:NW_INPUT
SET /P STATIC_IP=[IP:]
SET /P SUBNET=[Subnet Mask:]
SET /P GATEWAY=[Default Gateway:]
ECHO.
ECHO You specified:
ECHO IP Address: %STATIC_IP%
ECHO Subnet Mask: %SUBNET%
ECHO Default Gateway: %GATEWAY%
:NW_CONFIRM
ECHO.
SET /P NW_CONF=[Is this correct? Y/N:]
IF /I "%NW_CONF%" == "Y" GOTO NW_SET
IF /I "%NW_CONF%" == "N" GOTO NW_INPUT
GOTO NW_CONFIRM

:NW_SET_STATIC
netsh int ip add name="Local Area Connection" static %STATIC_IP% %SUBNET% %GATEWAY% 1
GOTO END

:NW_SET_DHCP
netsh int ip set add "Local Area Connection" dhcp
GOTO END

:END

Youre so great :)

greetz tron

Link to comment
Share on other sites

and when having more then 1 nw adapters? i have 3 adapters

hmmmm... something like this maybe? Haven't tested it so let me know if it works :P

@echo off
:NW_CHOOSE
ECHO.
ECHO 1. per DHCP
ECHO 2. Statische IP-Adresse
SET /P NW_CONF=[Do you want to use DHCP or specify a static IPs? (Select 1 or 2)]
IF /I "%NW_CONF%" == "1" GOTO NW_SET_DHCP
IF /I "%NW_CONF%" == "2" GOTO NW_INPUT

:NW_INPUT
ECHO Setup 1st Adapter:
SET /P STATIC_IP1=[IP:]
SET /P SUBNET1=[Subnet Mask:]
SET /P GATEWAY1=[Default Gateway:]
ECHO.
ECHO Setup 2nd Adapter:
SET /P STATIC_IP2=[IP:]
SET /P SUBNET2=[Subnet Mask:]
SET /P GATEWAY2=[Default Gateway:]
ECHO.
ECHO Setup 3rd Adapter:
SET /P STATIC_IP3=[IP:]
SET /P SUBNET3=[Subnet Mask:]
SET /P GATEWAY3=[Default Gateway:]

ECHO You specified:
ECHO Adapter 1 - IP: %STATIC_IP1% MASK: %SUBNET1% GW:%GATEWAY1%
ECHO Adapter 2 - IP: %STATIC_IP2% MASK: %SUBNET2% GW:%GATEWAY2%
ECHO Adapter 3 - IP: %STATIC_IP3% MASK: %SUBNET3% GW:%GATEWAY3%
:NW_CONFIRM
ECHO.
SET /P NW_CONF=[Is this correct? Y/N:]
IF /I "%NW_CONF%" == "Y" GOTO NW_SET_STATIC
IF /I "%NW_CONF%" == "N" GOTO NW_INPUT
GOTO NW_CONFIRM

:NW_SET_STATIC
netsh int ip add name="Local Area Connection" static %STATIC_IP1% %SUBNET1% %GATEWAY1% 1
netsh int ip add name="Local Area Connection 2" static %STATIC_IP2% %SUBNET2% %GATEWAY2% 1
netsh int ip add name="Local Area Connection 3" static %STATIC_IP3% %SUBNET3% %GATEWAY3% 1
GOTO END

:NW_SET_DHCP
netsh int ip set add "Local Area Connection" dhcp
netsh int ip set add "Local Area Connection 2" dhcp
netsh int ip set add "Local Area Connection 3" dhcp
GOTO END

:END

Link to comment
Share on other sites

it looks nice =)

cant test it now but how do i know which adapter is 2nd adapter,... ? ;)

when doing "ipconfig /?" in command line there is a switch "ipconfig /renew EL*" so i can use the Line for example ipconfig /renew 3COM*

isnt it possible with netsh too? hm it looks like not :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...