Information Technology Reference
In-Depth Information
Using a Command-Line Interface
The index = x syntax in the netsh interface ip add dns command will add a new DNS server
at the location specified by x . In this case, the numbering sequence starts at 1, so adding a DNS
server with index = 2 will place the new server second in the DNS search order. Any existing
DNS servers, including those specified by DHCP or Group Policy, will be moved down to make
room for the one you just added.
Using VBScript
DNS server information is stored in WMI as an array of IP addresses. A typical array consists of
a number of similar items (usually called elements ), each with an associated index that's used
to reference the item contained at that location. In most programming languages, array indexes
start at zero, not one, and VBScript is no exception. So an array of IP addresses called myArray
might be visualized like this:
myArray[0] = 10.0.0.1
myArray[1] = 10.0.0.2
myArray[2] = 10.0.0.154
In the case of the DNS search order, these array elements are read in order from index 0
through index (n - 1), where n is the number of elements in the array. This can sometimes be
confusing to people who are new to scripting or programming, so look at it this way: if there are
five elements in the array, they are located at 0, 1, 2, 3, and 4. In this case, n is equal to 5, and the
final element of the array is located at array index (n - 1), or 4.
One restriction of arrays is that you need to tell VBScript how large the array is before you
start using it. In this case, we do so by setting the array equal to the current array of DNS servers
configured in the DNS search order, like this:
arrDNSServerOrder = nic.DNSServerSearchOrder
In order to add a new server to this array, we need to first make the array one element
larger in order to hold the new value. We do this by using the command ReDim Preserve
arrDNSServerOrder(intNewArraySize) . Here, ReDim sets a new size for the array, and Preserve
ensures that the elements already present in the array will not be erased. (If we hadn't used
Preserve here, all existing entries in the arrDNSServerOrder array would have been erased.) As
you saw in the code comments, we then moved each element in the array to a position that was
one higher in the array, so that arrDNSServerOrder[4] was moved to arrDNSServerOrder[5] ,
and so forth. To add the new DNS server to the beginning of the search order, we finally added
the new server to arrDNSServerOrder[0] , which is the first element of the array.
See Also
￿MSDN: “VBScript Variables”
￿
Microsoft KB 200525: “Using NSLookup.exe”
Search WWH ::




Custom Search