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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i change the network cards properties?

Status
Not open for further replies.

ccaathl

MIS
Mar 7, 2001
35
US
Hello,

I am using a script that changes my laptop's network card properties from DHCP to a fixed IP address, with 2 DNS servers.

I have another script that changes it back to DHCP.

But I want the card to "obtain the DNS server address automatically" too.

What do i need to use to do this?


Hope someone can help.
Many thanks
T

The code I have for bringing the card back to using DHCP is:

**************
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
**************
 
Hello ccaathl,

objNetAddress.ipaddress returns an array. Hence the shortcut is to get it like this.
[tt]
wscript.echo objNetAdapter.ipaddress(0)
[/tt]
Sure you can check its ubound and exhaust its setting if so desired.

regards - tsuji
 
Hello,
Sorry, I must not have made it clear.

I need a script that will reset my network adapter so that it collects the TCP/IP and DNS settings automatically.

The script in my original posting above covers the TCP/IP part, but I need some additional code to get the card to obtain its DNS information automatically too.

Hope you can help
Many thanks
T
 
This script should help:

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()
    errDNS = objNetAdapter.SetDNSServerSearchOrder()
    errDDNs = objNetAdapter.SetDynamicDNSRegistration
     If errEnable = 0 Then
        Wscript.Echo "DHCP has been enabled."
    Else
        Wscript.Echo "DHCP could not be enabled."
    End If
Next

Thanks

Spong
 
Brilliant.
That's great, all sorted now.
Many thanks.
T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top