Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

W2K VB or VBScript to change IP

5 views
Skip to first unread message

Bob

unread,
Oct 4, 2002, 7:30:53 PM10/4/02
to
I have been looking for sample code to change the IP address of a Windows
2000 Pro Workstation.

Most of the time will be using DHCP and sometimes a static IP depending on
where I am.

Would appreciate some help if someone has code that will work. I have been
told to make two .reg files one for DHCP and one for my static ip, it does
not work on Windows 2000. Also hardware profiles that will not work for
what I want to do. I just want to compile an app that has my preset IP
addresses. To reply to me remove ATHOME from my address.

Thanks,
Bob

the Wiz

unread,
Oct 6, 2002, 10:38:08 PM10/6/02
to
"Bob" <BobAske...@attbi.com> wrote:

No matter how you do it, switching between DHCP and static IP addresses is
basically a matter of changing registry entries. Loading a .reg file and
rebooting is the most straight-forward way of doing this, since very little of
the intimately connected OS info in the registry is incorporated without a
reboot.

Network info is read and processed before the GUI is started in other versions
of Windows (watch the network adapter lights during a DHCP boot). A "hot
switch" without rebooting may not be available.


VB3 source code: http://thelabwiz.home.mindspring.com/vbsource.html
VB6 source code: http://thelabwiz.home.mindspring.com/vb6source.html
VB6 - MySQL how to: http://thelabwiz.home.mindspring.com/mysql.html
Fix the obvious to reply by email.

Bob

unread,
Oct 8, 2002, 10:09:41 PM10/8/02
to
I got some help with this and looks like the folowing script works. I also
ended up copying to VB6 and wrote my application with a few modifications
and it appears to work fine. Still have to test on different PCs though.

I created textboxes in my app that addresses can be copied to and then
executed.

Bob

To Enable DHCP:
Enables the DHCP client service on a computer. The computer will then use
DHCP to obtain an IP address rather than use a static IP address.
Script Code


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
If errEnable = 0 Then
Wscript.Echo "DHCP has been enabled."
Else
Wscript.Echo "DHCP could not be enabled."
End If
Next

CHANGE TO STATIC IP

The sample scripts are not supported under any Microsoft standard support
program or service. You can, however, report issues and bugs by sending
e-mail to scri...@microsoft.com.
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcen
ter/network/Scrnet01.asp
Configuring a Static IP Address
Description
Sets the IP address of a computer to 192.168.1.141, and sets the IP gateway
to 192.168.1.100.
Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")

strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")

strGatewayMetric = Array(1)


For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next

Determining a Computer's IP Address
Description
Returns the IP address for each IP-enabled network adapter installed in a
computer.

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _("Select IPAddress from
Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next


The System Administration Scripting Guide, part of the Windows .NET Server
Resource Kit. For more information, contact scri...@microsoft.com.


Bob Schor

unread,
Oct 11, 2002, 5:18:24 PM10/11/02
to
I seem to recall an application called NetSwitcher that, in fact, I have on my
laptop to enable me to ping-pong between various domains. It may be more than
you want, but it works well, is easy to use, and seems to do the job.

BS

Bob

unread,
Oct 14, 2002, 9:21:12 PM10/14/02
to
Yes I have checked NetSwither out but my main office did not want to use it.
I figured with all the time I have spent on this it would be a good option.


"Bob Schor" <bsc...@pitt.edu> wrote in message
news:3DA7401F...@pitt.edu...

0 new messages