Previous Page
Next Page

Using WMI to Assign Network Settings Step-by-Step Exercises

Let's practice using WMI to set various networking configuration properties. The result of this will become the Worker information section for use in the One Step Further section.

Caution

If this script were to be run in a production environment, it would turn on DHCP on the targeted machines. This could interrupt network communications. Please use this script in a practice environment first, and make the appropriate changes before ever running it in a production environment.


Instructions

1.
Open Microsoft Notepad or your favorite script editor.

2.
Open the \My Documents\Microsoft Press\VBScriptSBS\ch14\StepByStep\EnableDHCPStarter.vbs script and save it as YourNameEnableDHCP.vbs.

3.
On the first line, add the Option Explicit command.

4.
Change the variable strComputer to Target everywhere it is mentioned in the script. (The Find and Replace feature of Notepad is a good tool to use when renaming variables.)

5.
Change the variable objWMIService to oWMIService everywhere it is mentioned in the script.

6.
Change the variable objNetAdapter to oNetAdapter everywhere it is mentioned in the script.

7.
Declare all the variables used in the script by using the Dim command. You will need to declare seven variables: Target, oWMIService, oNetAdapter, colNetAdapters, DNSDomainErr, DNSsearchErr, and DNSserver.

8.
Modify the line errEnable = oNetAdapter.EnableDHCP() so that you can assign a DNS suffix for NWTraders.com. The line will look like the following:

DNSDomainErr = oNetAdapter.SetDNSDomain("NWTraders.com")

9.
Delete the Output section (the If...Then...Else section).

10.
Add a couple of DNS servers to the DNS search list. To do this, use the SetDNSsearch Order method. However, because the DNS server is stored as an array, you will need to make a couple of entries in the script. On the line below the Target = "." line, add the following code:

DNSserver = Array("128.1.2.1", "129.1.2.2")

11.
Add the SetDNSsearchOrder method under the SetDNSDomain line. Your code will look like the following:

DNSsearchErr=objNetAdapter.SetDNSServerSearchOrder(DNSserver)

12.
Add a couple of lines of code so that you know the result of your operation. To do this, you echo out the value of both DNSsearchErr and DNSDomainErr along with appropriate remarks. The code for this looks like the following:

WScript.Echo "DNSDomain returned " & (DNSDomainErr)
WScript.Echo "DNSsearchOrder returned " & (DNSsearchErr)

13.
Save your work as YourNameEnableDHCP.vbs. Run the script. You should see the IP address on your machine change to use a DHCP assigned address. If there is no DHCP server, then the machine will obtain an Automatic Private Internet Addressing (APIA) address. If this is not the case, then compare your script with the EnableDHCP.vbs script in the \My Documents\Microsoft Press\VBScriptSBS\ch14\StepByStep folder.


Previous Page
Next Page