configure network setting from bat file

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

kronz

Thread Starter
Joined
Aug 23, 2007
Messages
8
hey all... as the title says.. i was wondering if it is possible to create a bat file to configure the network settings on the computers on my network so i can give each computer its own ip.. and how i would go about doing it... thanks
 
Joined
Jun 20, 2007
Messages
317
No, I don't think you can assign IP addresses via a .bat file. However, that should be able to be done via a router.
 
Joined
Aug 7, 2007
Messages
9,028
This will do it. You have to know enough of the NIC description for each PC to get the proper Index. Most systems the Index for the primary NIC is 1, so it might work if you just set the values for Index=1

Check here for other values you can set if needed:
http://msdn.microsoft.com/en-us/library/aa394217(VS.85).aspx
For help with WMIC, type WMIC /? at a command prompt, or Google it

Code:
Set _NICName=Intel 21140
Set _IP=192.168.1.25
Set _SubMask=255.255.255.0
Set _DNS1=192.168.1.1
Set _Gateway=192.168.1.1
For /F "tokens=3 delims=," %%I in ('WMIC nicconfig get Description^, Index /FORMAT:CSV ^|Find /I "%_NICName%"') Do Set _Index=%%I
WMIC nicconfig where Index=%_Index% call EnableStatic ("%_IP%"), ("%_SubMask%")
WMIC nicconfig where Index=%_Index% call SetDNSServerSearchOrder ("%_DNS1%")
WMIC nicconfig where Index=%_Index% call SetGateways ("%_Gateway%")
HTH

Jerry
 
Joined
Jun 20, 2007
Messages
317
Nice Jerry! (y)

However, wouldn't something like that require individual .bat files on each machine? I could have misinterpreted the OP, but I read it as him/her wanting to basically setting static IPs from one location instead of having to move to each station.
 
Joined
Aug 7, 2007
Messages
9,028
Well, WMIC can be run remotely to configure PCs over the network, if you've given permission in the firewall for remote access and know the PC name. The systems would have to be configured for DHCP (which is the default) or already have a static IP setup to be accessed over the network. Best way to go for a network of any size, or one that is physically dispersed. Using DHCP is so much easier though. You can always reserve IPs to give the appearance of static IPs while keeping all configuration in one location.

Wouldn't need a file on each PC. The batch file could be on a public share if the PC's have network access, or just put on a floppy or USB drive.

I think in most cases the Index value for the NIC will be 1, so you could just assume that; then if you can create a list of computer names,IP desired you can use a FOR loop to read the file and get the IP, or pass the last digit as a command line parameter, or prompt for it. You could also list the NICs and prompt for the Index value if needed.

If you have both wired and wireless though, likely one will be 1 and one will be 2 -- you'd need to check the description in that case, or randomly assign an IP to each interface, as well as providing some way to detect that there are two interfaces to configure.

If you do have to get into the NIC description to find the correct Index value though, seems it would be easier to just configure the IP info through the normal Windows TCP/IP properties dialog.

All depends on the end use. If you want to re-configure a PC after an OS re-install it would save a step or two once you have a list of the PC names, Index number(s) if needed, and desired IP addresses. If you are restoring from an image though, just set the IP before taking the image. And for a one time deal to switch from DHCP to Static, seems it would be easier to do each PC using the TCP/IP dialog.

Jerry
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top