Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing IP Address for specific net adapters

Status
Not open for further replies.

acl03

MIS
Jun 13, 2005
1,077
US
I have seen this code (I think written by marcdmac). Is there a way to pull the network adapter name (ie. "Local Area Connection" or "Wireless Connection") from within the For loop?


Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
    
userInput = InputBox ("Enter IP Address:", "IP Address Change")


strIPAddress = Array(userInput)
strSubnetMask = Array("255.255.0.0")
strGateway = Array("150.142.x.x")
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



Thanks,
Andrew
 
not with that class. You will need to use

Win32_NetworkAdapter.

From there you can use the property NetConnectionID.

You can link the two classes using

Index and DeviceID


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top