This section provides an example of how to connect to the license controller in your domain and download the Per Seat licensing information for all the registered server products into a Microsoft Excel 4.0 spreadsheet. The following detailed comments describe the code example, written in Visual Basic for Applications (VBA), that is shown at the end of this section. A Microsoft Word for Windows 2.0x file (LLSOBJT.DOC) containing descriptions of the properties of all the objects listed in this example is included on the Windows NT Resource Kit CD.
You must first create an instance of the Llsmgr Application object via CreateObject or GetObject. The Llsmgr Application object is listed in the Registry under "Llsmgr.Application.1," but this registration takes place during the startup of the License Manager application. This means that for this, or any other, macro involving the Llsmgr Application object to work properly, the Registry must first be updated either by running License Manager at least once or by manually adding the Llsmgr Application object Registry entries via the Registry Editor configuration utility.
Once the Llsmgr Application object has been properly registered and an instance of the object has been created, you must next locate (and connect to) the domain's enterprise server (either the primary domain controller or some specific server in the domain that has been configured as the repository of license information). The SelectDomain method of the Llsmgr Application object does just that. Given a domain name, the Llsmgr Application object searches for the enterprise server for that domain and then connects. If no domain name is given, the Llsmgr Application object attempts to find the local domain's enterprise server.
Once you are connected to the enterprise server, you can query the Llsmgr Application object for an instance of the Controller object respresenting the enterprise server. The ActiveController property of the Llsmgr Application object does exactly that. With the enterprise server's Controller object, you can query for the licensing information in which you are interested.
In this example, you want to view the Per Seat status of all the products registered in the domain. The enterprise server's Controller object has a property called Products, which is a collection object that contains a Product object for each of the registered server products in the domain. The number of Product objects in the collection (and, therefore, the number of registered server products in the domain) is described in the collection object's property Count, and an individual Product object can be accessed via the collection object's method Item(). By enumerating over the entire Products collection, statistics for each of the server products in the domain can be easily obtained.
Each Product object has a property called InUse and another called PerSeatLimit. The former describes the number of Per Seat licenses currently being consumed for the server product, and the latter describes the total number of Per Seat licenses registered for the server product. Simply by querying the properties of these objects, you can quickly determine license compliance status as well as server product usage to make more informed decisions about license and product purchases.
The preceding has described the following VBA code example:
Sub GetProducts() Dim Llsmgr As Object Set Llsmgr = CreateObject("Llsmgr.Application.1") Llsmgr.SelectDomain Dim EnterpriseServer As Object Set EnterpriseServer = Llsmgr.ActiveController Dim Products As Object Set Products = EnterpriseServer.Products Dim nProducts As Long nProducts = Products.Count Range("A1").Value = "Product Name" Range("B1").Value = "Licenses Purchased" Range("C1").Value = "Licenses In Use" Dim index As Long Dim Product As Object While nProducts nProducts = nProducts - 1 Set Product = Products.Item(nProducts) ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.Offset(0, 0).Range("A1").Value = Product.Name ActiveCell.Offset(0, 1).Range("A1").Value = Product.PerSeatLimit ActiveCell.Offset(0, 2).Range("A1").Value = Product.InUse
Wend End Sub