For Programmers: Free Programming Magazines  


Home > Archive > Windows Server Scripting > July 2004 > Change NIC's IP address









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Change NIC's IP address
stev379

2004-07-30, 3:55 pm

On a PC with more than one NIC installed. We only want to
change the address on one card. How can we point the
script to just one card? The card in question is a Dlink
NIC pcmcia card.

'Begin script
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer_
& "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration_
where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.xxx")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.xxx")
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

'End Script

Thanks!!
-Steve
Torgeir Bakken \(MVP\)

2004-07-30, 3:55 pm

stev379 wrote:

> On a PC with more than one NIC installed. We only want to
> change the address on one card. How can we point the
> script to just one card? The card in question is a Dlink
> NIC pcmcia card.
>
> (snip code)

Hi

In the For Each loop, test on the objNetAdapter.Description property.


For my computer, I would need to do like this to hit my 3Com adapter:


If LCase(objNetAdapter.Description) = _
LCase("3Com 10/100 Mini PCI Ethernet Adapter") Then
' do something here
End If



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/sc...er/default.mspx
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com