Re: Remove Default Gateway
anonymous_at_discussions.microsoft.com
Date: 03/22/04
- Next message: Stev379: "Re: Remove Default Gateway"
- Previous message: Nuno Silva: "GetDetailsOf - Files Summary in properties"
- In reply to: Michael Holzemer: "Re: Remove Default Gateway"
- Next in thread: Stev379: "Re: Remove Default Gateway"
- Reply: Stev379: "Re: Remove Default Gateway"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 21 Mar 2004 19:58:46 -0800
I'm getting an error that the "Gateway could not be
removed" per the defined message in the script. I was the
getting the same error with the full script including DHCP
and DNS. The DHCP and DNS portions work on their own but
I can't get the gateway to remove. Any clue as to where I
went wrong?
Thanks
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer
& "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration
where IPEnabled=TRUE")
GW = Array ()
Metric = Array()
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress,
strSubnetMask)
errGW = objNetAdapter.SetGateways(strGateway,
strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The Gateway has been removed."
Else
WScript.Echo "The Gateway could not be changed."
End If
Next
>-----Original Message-----
>In item <192201c40f01$5b05d7b0$3a01280a@phx.gbl>,
>Stev379 says...
>
>> The script below enables DHCP and removes the DNS
>> addresses, but the static gateway settings stay. How
can
>> I remove the static gateway settings?
>>
>> Thanks!
>> -Steve
>>
>>
>>
>>
>> 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
>>
>> On Error Resume Next
>> Const FULL_DNS_REGISTRATION = True
>> Const DOMAIN_DNS_REGISTRATION = False
>> strComputer = "."
>> Set objWMIService = GetObject("winmgmts:\\" &
strComputer
>> & "\root\cimv2")
>> Set colNetCards = objWMIService.ExecQuery _
>> ("Select * From Win32_NetworkAdapterConfiguration
>> Where IPEnabled = True")
>> For Each objNetCard in colNetCards
>> objNetCard.SetDynamicDNSRegistration
>> FULL_DNS_REGISTRATION, DOMAIN_DNS_REGISTRATION
>>
>>
>> errEnable = objNetCard.SetDNSServerSearchOrder
>> (arrDNSServers)
>> If errEnable = 0 Then
>> WScript.Echo "Dynamic DNS is enabled."
>> Else
>> WScript.Echo "Dynamic DNS is not enabled."
>> End If
>> Next
>
>You need to set the gateway with an empty array.
>I also edited this a little to combine both scripts you
>do not need both.
>
>'// Set the gateway and metric to empty arrays
>aGW = Array ()
>aMetric = Array()
>
>
>For Each objNetAdapter In colNetAdapters
>
>'// Add this line to your code
>errGW = objNetAdapter.SetGateways(aGW, aMetric)
>'// You can then check for an error
>If errGW = 0 then
>....
><snip>
>
> errEnable = objNetAdapter.EnableDHCP()
>
>'// Then instead of running two scripts
>'// you can put everything into one
>'// This way you attach once to the computer,
>'//then take care of all settings
>'// Clear the static DNS then set dynamic
> errDNS = objNetAdapter.SetDNSServerSearchOrder()
> errDDNS = objNetAdapter.SetDynamicDNSRegistration
>
> If errDNS = 0 then
> ...
> <snip>
>
> If errEnable = 0 Then
> Wscript.Echo "DHCP has been enabled."
> Else
> Wscript.Echo "DHCP could not be enabled."
> End If
>
>--
>Regards,
>
>Michael Holzemer
>No email replies please - reply in newsgroup
>
>Learn script faster by searching here
>http://www.microsoft.com/technet/community/scriptcenter/de
fault.mspx
>
>
>.
>
- Next message: Stev379: "Re: Remove Default Gateway"
- Previous message: Nuno Silva: "GetDetailsOf - Files Summary in properties"
- In reply to: Michael Holzemer: "Re: Remove Default Gateway"
- Next in thread: Stev379: "Re: Remove Default Gateway"
- Reply: Stev379: "Re: Remove Default Gateway"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|