WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mcvpjd3 on October 11, 2016, 07:02:26 AM

Title: IP Address change
Post by: mcvpjd3 on October 11, 2016, 07:02:26 AM
Hi Folks, one of my users has asked me to write a script which I though might be an easy script. The more I think about it the less easy it seems to be so just wondered if anyone here has done anything similar.

What I need is a script to change from a DHCP IP to a Static IP for a laptop. The difficulty is this may be required on more that one laptop with different hardware or LAN names. I started looking into using WMI to get network adaptors but it seems messy and overly complicated.

Has anyone done anything like this or some way of listing the entries available in "Network Connections" on a Win7 PC?

Thanks
Title: Re: IP Address change
Post by: td on October 11, 2016, 07:17:41 AM
The Tech Database is usually a good place to start:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/How~To+Change~Ip~Address.txt (http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/How~To+Change~Ip~Address.txt)
Title: Re: IP Address change
Post by: pamsniffer on November 05, 2016, 04:45:33 AM
look at netsh

netsh interface ip add dns "connection name" 208.67.222.222
Title: Re: IP Address change
Post by: snowsnowsnow on November 05, 2016, 06:54:22 AM
netsh is definitely the way to go, but I think the problem here (in this thread) is that the OP wants it to be more "user-proof" than netsh is by default.  That is, he wants it to figure out the various bits of detail (ip addr, DNS, netmask, etc) that are needed by netsh "automatically".

To put this another way, I've written scripts (actually, ordinary DOS/Windows batch files, not WBT scripts) to do this - that is, to switch back and forth between DHCP and static IP - and I've found both of the following to be true:
1) It is not trivial.  By the time you're done, you've got quite a lengthy script on your hands.
2) It requires a fair amount of user input - i.e., the presumed user has to pretty much know what is going on and what needs changing.  Luckily, the presumed user of most of my scripts is, you guessed it, me.

P.S.  Just out of curiosity, why are you doing this?  I.e., anytime people start asking about static IP, the obvious question that eventually comes out is: Why?