WSH code to change local IP configuration 
Author Message
 WSH code to change local IP configuration

Hi people,

I was wondering if anyone can give me any hints or code to perform the
following.....

I use my laptop on a work LAN which uses DHCP, and on a home LAN for which I
have a static IP address.

Is there a way I can swap the IP settings on my machine between DHCP and
static settings via WSH.

I'm using Win2K Pro

Any help appreciated
Stu

--
=================================
Stuart Parker - Consultant
MCP, MCP+I, MCSE, MCT
Web: www.uridium.co.uk

ICQ: 6930722
=================================



Mon, 27 Jan 2003 03:00:00 GMT  
 WSH code to change local IP configuration

Attached is a post from last March by 'Legolas' that shows the needed settings.

--

link to FAQ for OE 5.5

Mark L. Ferguson    Please reply in Newsgroup
marfer's notes for OE 5.0 > http://www.geocities.com/SiliconValley/Bay/6386/IE_ng_notes.htm

Quote:

> Hi people,

> I was wondering if anyone can give me any hints or code to perform the
> following.....

> I use my laptop on a work LAN which uses DHCP, and on a home LAN for which I
> have a static IP address.

> Is there a way I can swap the IP settings on my machine between DHCP and
> static settings via WSH.

> I'm using Win2K Pro

> Any help appreciated
> Stu

> --
> =================================
> Stuart Parker - Consultant
> MCP, MCP+I, MCSE, MCT
> Web: www.uridium.co.uk

> ICQ: 6930722
> =================================

[ Attached Message ]

From:
To:
Date: Wed, 22 Mar 2000 10:47:49 +0100
Local: Wed, Mar 22 2000 4:47 am
Subject: Re: Finding the IP address of a client
Little correction for who, like me, use DHCP... ;)

Option Explicit
on error resume next

Dim  WSHShell

' Create Objects
Set WSHShell = WScript.CreateObject("WScript.Shell")

call main()

' FUNCTIONS HERE
Sub GetIP
        Dim CardType
        Dim MyIP
        Dim booDHCP
        Dim i

        'What Kind of Card is it
        CardType = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1\ServiceName")

        booDHCP = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & CardType & "\Parameters\Tcpip\EnableDHCP")

        if booDHCP then
                MyIP = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & CardType & "\Parameters\Tcpip\DHCPIPAddress")
                WScript.Echo MyIP
        else
                MyIP = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & CardType & "\Parameters\Tcpip\IPAddress")
                for i = 0 to UBOUND(MyIP)
                        WScript.Echo MyIP(i)
                next
        end if

end Sub

'Run it From Here
Sub main()
GetIP()
End Sub

.Enjoy.
Legolas

- Show quoted text -

Quote:


> Hi Everyone,

> How do I pull the local IP of a client PC?  We are using WSH 2.0 and

> VBScript for their login scripts.  The problem is that I cannot pull

> the IP from the registry due to the key type being REG_MULTI_SZ.  I
> can pull other types of keys just fine using the RegRead function.

> I have also tried the method on Ian's site (www.windows-script.com),

> but I don't seem to have the right control registered for the
> Mswinsock.winsock function.  What control should I use?

> Any help would be greatly appreciated!!  Please feel free to email me
> (just removed the obvious mistakes) or post your reply here.  Thanks

> again for the help.

> > Brian



Mon, 27 Jan 2003 03:00:00 GMT  
 WSH code to change local IP configuration

Here is a WMI script that I have used to assign a stactic IP address.
Set Adapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=12")

 ipaddr = array("199.250.186.204")
 subnet = Array("255.255.255.224")
 gateway = array("199.250.186.222")
 DNS = array("199.250.186.225")

 RetVal = Adapter.EnableStatic(ipaddr,subnet)
 adapter.setgateways(gateway)
 Adapter.SetDnsServerSearchOrder(DNS)

 if RetVal = 0 then
  WScript.Echo "DHCP disabled, using static IP address"
 else
  WScript.Echo "DHCP disable failed"

End if


Quote:
> Hi people,

> I was wondering if anyone can give me any hints or code to perform the
> following.....

> I use my laptop on a work LAN which uses DHCP, and on a home LAN for which
I
> have a static IP address.

> Is there a way I can swap the IP settings on my machine between DHCP and
> static settings via WSH.

> I'm using Win2K Pro

> Any help appreciated
> Stu

> --
> =================================
> Stuart Parker - Consultant
> MCP, MCP+I, MCSE, MCT
> Web: www.uridium.co.uk

> ICQ: 6930722
> =================================



Wed, 29 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. vbscript to change local ip address

2. Changing TCP/IP properties using wsh

3. Change IP Settings in WSH Script

4. WSH to change a machine from Static IP to Dynamic

5. Can I change IP settings using WSH??

6. Change IP info with WSH?

7. ip configuration

8. WBEM IP configuration sample

9. changing of IP-address and other IP parameters

10. changing of IP-address and other IP parameters

11. Initial configuration codes

12. Changing DNS Configuration of Network Card

 

 
Powered by phpBB® Forum Software