Information Technology Reference
In-Depth Information
Note If you've renamed the network connection from the default of Local Area Connection , you'll
need to adjust the previous syntax accordingly.
Using the Registry
To configure the gateway metric, configure the following Registry value:
[HKEY_LOCAL_MACHINE\SYSTEM\Current Control Set\Services\
Tcpip\Parameters\ Interfaces\ {<Interface GUID>} ]
"DefaultGatewayMetric"=REG_MULTI_SZ:"< Metric> "
Caution If you are configuring metrics for multiple interfaces, you need to list the gateway metrics in the
same order that the gateways are listed in the DefaultGateway key.
Using VBScript
This code configures the local interface with a default gateway of 10.0.0.1 and a metric of 1 .
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strGateway = Array("10.0.0.1") ' Modify this value as needed
strGatewayMetric = Array(1) ' Modify this value as needed
' --------- END CONFIGURATION ------
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set adapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each a in adapters
errGateways = a.SetGateways(strGateway, strGatewaymetric)
If errGateways = 0 Then
WScript.Echo "Success! The default gateway has been set."
Else
WScript.Echo "Error! The default gateway could not be set."
End If
Next
How It Works
In TCP/IP, the default gateway associated with an IP address indicates the path through which
all non-local traffic should be routed. On a device with only one configured gateway, all traffic
will be directed to that one gateway address. If you have a multi-homed computer or a device
Search WWH ::




Custom Search