Programming Microsoft Outlook and Microsoft Exchange 2003, Third Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Programming Microsoft Outlook and Microsoft Exchange 2003, Third Edition [Electronic resources] - نسخه متنی

Thomas Rizzo

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید











Windows Management Instrumentation

Besides using CDOEXM to manage your Exchange infrastructure, you can also use the WMI providers that ship with Exchange.

































Table 18-8: WMI Classes Available in Exchange 2000

Class


Description


ExchangeLink


Contains information about message-handling links between servers. This class can contain zero or more ExchangeQueue objects.


ExchangeQueue


Contains information about the dynamic queues that are created to transfer messages between mail servers.


ExchangeConnectorState


Provides information about a connector and its current state.


ExchangeServerState


Provides information about your Exchange server and its current status.


ExchangeClusterResource


Provides information about a clustered resource in an Exchange clustered environment.


Exchange_DSAccessDC


Provides information about the domain controllers available to the Exchange DSAccess component.


Exchange_MessageTrackingEntry


Provides information about events that have happened to a message as it goes through the Exchange system.


Exchange 2003 adds a large number of new classes and some additional capabilities to existing WMI classes (such as ExchangeLink). Table 18-9 lists the new classes. I won't cover all of them in detail—just the new classes that you are most likely to use in your applications.








































































Table 18-9: WMI Classes Available in Exchange 2003

Class


Description


Exchange_FolderTree


Contains information about folder tree hierarchies in Exchange.


Exchange_Link


Contains information about links between servers. Provides more capabilities than the ExchangeLink class.


Exchange_Logon


Contains logon information for the Exchange server, such as last logon time, client version used, and open message count.


Exchange_Mailbox


Contains mailbox information for a user, including total size of the mailbox, last logon time, and storage limit information.


Exchange_PublicFolder


Contains information about public folders in the system.


Exchange_Queue


Contains information about Exchange queues.


Exchange_QueueCacheReloadEvent


Contains information about the last time the queue updated its data.


Exchange_QueueData


Contains information about a queue that is available in XML format.


Exchange_QueuedMessage


Contains information about a queued message.


Exchange_QueuedSMTPMessage


Contains information about a queued SMTP message.


Exchange_QueuedX400Message


Contains information about a queue's X400 message.


Exchange_QueueSMTPVirtualServer


Enables or disables SMTP virtual servers.


Exchange_QueueVirtualServer


Contains information about Exchange virtual servers.


Exchange_QueueVirtualX400Server


Contains information about a virtual X400 server.


Exchange_ScheduleInterval


Sets the schedule interval for your server.


Exchange_Server


Contains information about your Exchange server, such as whether the server is a front-end server, and the Exchange version number.


Exchange_SMTPLink


Contains information about an Exchange SMTP link.


Exchange_SMTPQueue


Contains information about Exchange SMTP queues.


Exchange_X400Link


Contains information about X400 links.


Exchange_X400Queue


Contains information about X400 queues.


Besides the Exchange WMI providers and classes, other providers and classes ship with other software products and Windows. Table 18-10 describes some of these other WMI providers.



























Table 18-10: Other WMI Providers

Provider


Description


Event Log Provider


Provides information, notification, and access to the Windows Event Log.


Performance Monitor Provider


Provides notification and access to performance monitor data.


Registry Event Provider


Provides notifications when changes happen in the registry.


Registry Provider


Provides access to registry information.


SNMP Provider


Provides access and notification from Simple Network Management Protocol (SNMP) devices.



Exchange WMI Classes


The Exchange WMI classes are well documented in the SDK, so I won't go into detail on each one. Instead, I'll show how to code to these classes from an application. I'll highlight some of the key properties for the classes. The SDK is included with the book's sample files, so you can browse through the details of each class there.

The Exchange WMI classes are located in the WMI namespace \\.\root\cimv2\Applications\Exchange. You can access WMI in two ways. If you are used to standard programming, the easiest way is to use CreateObject. The following code creates the WMI locator that allows you to connect to a local or remote WMI namespace. It then calls the ConnectServer method of the WMI locator and passes the name of the server and the namespace to connect to. Finally, the code uses the InstancesOf method to retrieve an instance of a couple of the Exchange classes.

strConnectServer = "thomriznt52"
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(strConnectServer, _
"root/cimv2/applications/exchange")
Set Clusters = objService.InstancesOf("ExchangeClusterResource")
Set ExchangeLinks = objService.InstancesOf("ExchangeLinks")
Set ExchangeServerState = objService.InstancesOf("ExchangeServerState")

The other way to get the WMI objects is the same way you retrieve ADSI objects—using the GetObject method. The following code accomplishes the same thing as the previous code:

Set Clusters = GetObject("winmgmts:{impersonationLevel=" _
& "impersonate}!/root/cimv2/applications/exchange" _
).InstancesOf("ExchangeClusterResource")
Set ExchangeLinks = GetObject("winmgmts:{impersonationLevel= " _
& "impersonate}!/root/cimv2/applications/exchange" _
).InstancesOf("ExchangeLinks")
Set ExchangeServerState = GetObject("winmgmts:{impersonationLevel=" _
& "impersonate}!/root/cimv2/applications/exchange" _
).InstancesOf("ExchangeServerState")

Notice that instead of using LDAP:// in the GetObject call, we use winmgmts: to specify WMI. No matter which method you use, the same classes are returned. I prefer using the winmgmts: method.

Once you get the classes, retrieving properties from the WMI classes is straightforward. First you have to determine the number of instances in the class if the class has multiple instances. (For example, Win32_Processor might have multiple instances if the machine has multiple processors.) To do this, you can use the count property on the class that is returned or you can use a For..Each loop to loop through each instance.

Once you have an instance, you can retrieve or set properties on that instance. To retrieve a property, you specify the property just as you would for any other type of object you program against. The following example displays information about your Exchange server by using the ExchangeServerState class:

strConnectServer = "thomriznt52"
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(strConnectServer, _
"root/cimv2/applications/exchange")
Set ExchangeServerState = objService.InstancesOf("ExchangeServerState")
For Each ExchangeServer In ExchangeServerState
MsgBox "Exchange Server Name: " & ExchangeServer.Name
MsgBox "Exchange Server State: " & ExchangeServer.ServerStateString
MsgBox "Exchange Server State: " & ExchangeServer.ServerStateString
MsgBox "Exchange Server CPU State: " & ExchangeServer.CPUStateString
MsgBox "Exchange Server Disks State: " & ExchangeServer.DisksStateString
MsgBox "Exchange Server Services State: " _
& ExchangeServer.ServicesStateString
Next


WMI Query Language (WQL)


WMI provides a SQL query language for querying WMI providers for specific criteria. Rather than having to write looping code, you can use this query language to search for information in WMI. WQL, as you can see in the following example, is similar to SQL. Also, you only need to call the ExecQuery method on WMI to execute your queries. I'll cover only data queries here, but you can also create event and schema queries in WMI. These types of queries allow you to look for specific system events or query on specific schemas in WMI. The following example finds out whether the services on the Exchange Server are OK:

Set oExServer = GetObject("winmgmts:{impersonationLevel=" _
& "impersonate}!/root/cimv2/applications/exchange" _
).ExecQuery("SELECT * FROM ExchangeServerState " _
& "WHERE ServicesState = 0 OR ServicesState = 2 " _
& "OR ServicesState = 3")

This is just a quick look at what you can do with Exchange Server and WMI; you should learn more about WMI in general on your own. WMI provides a universal way to access not only Exchange Server management information but also a host of Windows and other Microsoft product information. It is a general-use Application Programming Interface (API) that is very useful if you are writing programs to manage Windows-based servers. (See the WMI section in MSDN for more information.)


The Antivirus API


I want to mention the Antivirus API (AVAPI)—also called the Virus Scanning API (VS API)—so you know that it exists and that independent software vendors (ISVs) can write to it. I don't expect non-antivirus software vendors to write to this API—or even care about it. But as a developer, you can use the performance counters and logging that the API provides to display information in your applications about successful scans, number of quarantined messages, loading and unloading of vendor DLLs, and the number of detected viruses.


/ 227