Previous Page
Next Page

Using the Exchange_Logon Class Step-by-Step Exercises

In this section, you use the Exchange_Logon class from the MicrosoftExchangeV2 namespace.

1.
Open the \My Documents\Microsoft Press\VBScriptSBS\Templates\Blank Template.vbs script in Microsoft Notepad or another script editor and save it as YourNameExchangeLogon.vbs.

2.
As the first non-commented line of the script, type Option Explicit.

3.
You need to declare six variables: strComputer, wmiNS, wmiQuery, objWMIService, colItems, and objItem. In addition, add On Error Resume Next, but comment out the line during development. The completed Header information section of your script will look like the following:

Option Explicit
'On Error Resume Next
Dim strComputer
Dim wmiNS
Dim wmiQuery
Dim objWMIService
Dim colItems
Dim objItem

4.
Assign the variable strComputer to be equal to ".". This line of code will look like the following:

strComputer = "."

5.
Use the variable wmiNS to hold the string "\root\MicrosoftExchangeV2". This line of code looks like the following:

wmiNS = "\root\MicrosoftExchangeV2"

6.
Use the wmiQuery variable to be hold the string "Select * from Exchange_Logon". This line of code looks like the following:

wmiQuery = "Select * from Exchange_Logon"

7.
Set the variable objWMIService to be equal to the object that comes back from using the GetObject command into WMI. Use the winmgmts moniker, specify strComputer as the target computer, and specify wmiNS as the target namespace. This line of code looks like the following:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)

8.
Set the colItems variable to hold the data that comes back from running the query contained in the variable wmiQuery when you use the ExecQuery method. This line of code looks like the following:

Set colItems = objWMIService.ExecQuery(wmiQuery)

9.
Create an empty For Each...Next statement. Use objItem as your placeholder, and use colItems as the collection to be iterated through. This will look like the following:

For Each objItem In colItems

Next

10.
Open the \My Documents\Microsoft Press\VBScriptSBS\ch20\StepByStep\StarterFileForExchangeLogon.txt file. This file contains the series of WScript.Echo commands that goes inside the empty For Each...Next statement that was created in step 9.

11.
Copy all the WScript.Echo commands contained in \My Documents\Microsoft Press\VBScriptSBS\ch20\StepByStep\StarterFileForExchangeLogon.txt and paste them into the For Each...Next statement. When completed, the script will look like the following:

For Each objItem In colItems
  WScript.Echo "AdapterSpeed: " & objItem.AdapterSpeed
  WScript.Echo "Caption: " & objItem.Caption
  WScript.Echo "ClientIP: " & objItem.ClientIP
  WScript.Echo "ClientMode: " & objItem.ClientMode
  WScript.Echo "ClientName: " & objItem.ClientName
  WScript.Echo "ClientVersion: " & objItem.ClientVersion
  WScript.Echo "CodePageID: " & objItem.CodePageID
  WScript.Echo "Description: " & objItem.Description
  WScript.Echo "FolderOperationRate: " _
    & objItem.FolderOperationRate
  WScript.Echo "HostAddress: " & objItem.HostAddress
  WScript.Echo "InstallDate: " & objItem.InstallDate
  WScript.Echo "LastOperationTime: " & objItem.LastOperationTime
  WScript.Echo "Latency: " & objItem.Latency
  WScript.Echo "LocaleID: " & objItem.LocaleID
  WScript.Echo "LoggedOnUserAccount: " _
    & objItem.LoggedOnUserAccount
  WScript.Echo "LoggedOnUsersMailboxLegacyDN: " & objItem.LoggedOnUsersMailboxLegacy
DN
  WScript.Echo "LogonTime: " & objItem.LogonTime
  WScript.Echo "MacAddress: " & objItem.MacAddress
  WScript.Echo "MailboxDisplayName: " & objItem.MailboxDisplayName
  WScript.Echo "MailboxLegacyDN: " & objItem.MailboxLegacyDN
  WScript.Echo "MessagingOperationRate: " _
    & objItem.MessagingOperationRate
  WScript.Echo "Name: " & objItem.Name
  WScript.Echo "OpenAttachmentCount: " _
    & objItem.OpenAttachmentCount
  WScript.Echo "OpenFolderCount: " & objItem.OpenFolderCount
  WScript.Echo "OpenMessageCount: " & objItem.OpenMessageCount
  WScript.Echo "OtherOperationRate: " & objItem.OtherOperationRate
  WScript.Echo "ProgressOperationRate: " _
    & objItem.ProgressOperationRate
  WScript.Echo "RowID: " & objItem.RowID
  WScript.Echo "RPCSucceeded: " & objItem.RPCSucceeded
  WScript.Echo "ServerName: " & objItem.ServerName
  WScript.Echo "Status: " & objItem.Status
  WScript.Echo "StorageGroupName: " & objItem.StorageGroupName
  WScript.Echo "StoreName: " & objItem.StoreName
  WScript.Echo "StoreType: " & objItem.StoreType
  WScript.Echo "StreamOperationRate: " _
    & objItem.StreamOperationRate
  WScript.Echo "TableOperationRate: " & objItem.TableOperationRate
  WScript.Echo "TotalOperationRate: " & objItem.TotalOperationRate
  WScript.Echo "TransferOperationRate: " _
    & objItem.TransferOperationRate
WScript.Echo "-=-"
Next

12.
Save and run the script by using CScript. If it does not appear to provide the information you expect, compare it with \My Documents\Microsoft Press\VBScriptSBS\ch20\StepByStep\ExchangeLogon.vbs.


Previous Page
Next Page