Subscribe to Windows IT Pro
February 23, 2009 12:00 AM

How AddressBasedPrinter.vbs Works

Windows IT Pro
InstantDoc ID #101231
Rating: (0)
Downloads
101231.zip

Executive Summary:
Using Windows Management Instrumentation (WMI), Windows Script Host (WSH), and a lot of creative coding, Alex K. Angelopoulos developed AddressBasedPrinter.vbs. This VBScript script determines which site a mobile user is in, then creates printer mappings for the appropriate printers at that site.

AddressBasedPrinter.vbs in Listing 1 performs many tasks to determine which site a mobile user is in and create mappings to the appropriate printers at that site. Here's a brief overview of how it works.

The script's first main task is to collect the TCP/IP-enabled Win32_NetworkAdapterConfiguration instances from the local computer. As callout A shows, for each configuration, it retrieves the IP addresses and subnet masks from the IPAddress and IPSubnet properties, respectively. After making sure these properties aren't empty, the script uses the NetworkID function in callout E to compute network IDs from the IP addresses and subnet masks. For example, if a computer has an IP address of 192.168.1.72 and a subnet mask of 255.255.255.0 associated with that address, the network ID for the computer—and all the other computers on the same network—will be 192.168.1.0. (For information about how this function works, see the web-exclusive Windows IT Pro article "Rem: How to Use WMI to Calculate a Computer's Network ID from Its IP Address and Network Mask." The script adds the IDs to the networkIDs dictionary as keys. Using the Scripting Runtime Library's Dictionary object is better than using an array because you don't know how many network IDs there will be. By storing them in a dictionary at this point, you avoid having to micromanage a resizable array. In the last line in callout A, the script extracts the networkIDs dictionary's keys and assigns them to the IDList array.

Next, the script creates another dictionary named Locations to hold the site names and network IDs specified in callout B. The code in callout C uses the Locations dictionary to determine which site the mobile user is in.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.