WMS WMI Event Handler Plug-in Properties
The WMS WMI Event Handler plug-in makes it possible to capture events through Windows Management Instrumentation (WMI). WMI is the Microsoft implementation of Web-Based Enterprise Management (WBEM), which is an industry initiative to develop a standard technology for accessing management information in an enterprise environment. WMI uses the Common Information Model (CIM) industry standard to represent systems, applications, networks, devices, and other managed components in an enterprise environment. For administration information about this plug-in, see Windows Media Services Help.
You can use the IWMSWMIBridgeAdmin interface to configure the ExposedEventClasses property of the WMS WMI Event Handler plug-in. This is illustrated in the following examples.
Visual Basic .NET Example
Imports Microsoft.WindowsMediaServices.Interop
Imports System.Runtime.InteropServices
Private Sub SetWMIPluginProps()
' Declare variables.
Dim Server As WMSServer
Dim Plugin As IWMSPlugin
Dim WMIBridgeAdmin As IWMSWMIBridgeAdmin
Try
' Create a new WMSServer object.
Server = New WMSServer()
' Retrieve the IWMSPlugin object for the
' WMS WMI Event Handler plug-in.
Plugin = Server.EventHandlers("WMS WMI Event Handler")
' Retrieve the administrative interface for the plug-in.
WMIBridgeAdmin = Plugin.CustomInterface()
' Specify the event classes to be handled
' by the plug-in.
WMIBridgeAdmin.ExposedEventClasses = _
WMS_EVENT_CLASS.WMS_WMI_CLASS_LIMIT_HIT Or _
WMS_EVENT_CLASS.WMS_WMI_CLASS_SERVER Or _
WMS_EVENT_CLASS.WMS_WMI_CLASS_PUBLISHING_POINT
Catch excCom As COMException
' TODO: Handle COM exceptions.
Catch exc As Exception
' TODO: Handle exceptions here.
Finally
' TODO: Perform clean-up here.
End Try
End Sub
C# Example
using Microsoft.WindowsMediaServices.Interop;
using System.Runtime.InteropServices;
// Declare variables.
WMSServer Server;
IWMSPlugin Plugin;
IWMSWMIBridgeAdmin WMIBridgeAdmin;
try
{
// Create a new WMSServer object.
Server = new WMSServerClass();
// Retrieve the IWMSPlugin object for the
// WMS WMI Event Handler plug-in.
Plugin = Server.EventHandlers["WMS WMI Event Handler"];
// Retrieve the administrative interface for the plug-in.
WMIBridgeAdmin = (IWMSWMIBridgeAdmin)Plugin.CustomInterface;
// Specify the event classes to be handled by the plug-in.
WMIBridgeAdmin.ExposedEventClasses =
WMS_EVENT_CLASS.WMS_WMI_CLASS_LIMIT_HIT |
WMS_EVENT_CLASS.WMS_WMI_CLASS_SERVER |
WMS_EVENT_CLASS.WMS_WMI_CLASS_PUBLISHING_POINT;
}
catch (COMException comExc) {
// TODO: Handle COM exceptions.
}
catch (Exception exc)
{
// TODO: Handle exceptions here.
}
finally
{
// TODO: Perform clean-up here.
}
C++ Example
#include <windows.h>
#include <atlbase.h>
// To access system plug-in interfaces, the
// type library must be imported as shown.
#import "WMSServerTypeLib.dll" no_namespace named_guids \
raw_interfaces_only
// Declare variables and interface pointers.
IWMSServer* pServer = NULL;
IWMSPlugins* pPlugins = NULL;
IWMSPlugin* pPlugin = NULL;
IDispatch* pDispatch = NULL;
IWMSWMIBridgeAdmin* pWMIBridgeAdmin = NULL;
CComVariant varIndex;
HRESULT hr = S_OK;
// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
NULL,
CLSCTX_ALL,
IID_IWMSServer,
(void **)&pServer);
if (FAILED(hr)) goto EXIT;
// Retrieve a pointer to an IWMSPlugins interface
// containing the collection of event handler plug-ins.
hr = pServer->get_EventHandlers(&pPlugins);
if (FAILED(hr)) goto EXIT;
// Retrieve a pointer to the IWMSPlugin interface for the
// WMS WMI Event Handler plug-in.
varIndex = "WMS WMI Event Handler";
hr = pPlugins->get_Item(varIndex, &pPlugin);
if (FAILED(hr)) goto EXIT;
// Retrieve an IDispatch pointer to the
// administration interface for the plug-in.
hr = pPlugin->get_CustomInterface(&pDispatch);
if (FAILED(hr)) goto EXIT;
// Call QueryInterface() to retrieve a pointer to the
// IWMSWMIBridgeAdmin interface.
hr = pDispatch->QueryInterface(IID_IWMSWMIBridgeAdmin, (void**)&pWMIBridgeAdmin);
if (FAILED(hr)) goto EXIT;
// Specify the event classes to be handled
// by the plug-in.
DWORD dwEventClasses = WMS_WMI_CLASS_LIMIT_HIT |
WMS_WMI_CLASS_SERVER |
WMS_WMI_CLASS_PUBLISHING_POINT;
hr = pWMIBridgeAdmin->put_ExposedEventClasses(
(WMS_EVENT_CLASS)dwEventClasses);
if (FAILED(hr)) goto EXIT;
EXIT:
// TODO: Release temporary COM objects and uninitialize COM.
The simplest way to capture exposed WMI events is through the WMI scripting API. The following Visual Basic Scripting Edition (VBScript) example uses SwbemServices and SWbemSink to query for events and display event properties.
VBScript Example
' Declare objects.
Dim Server As WMSServer
Dim Services As SWbemServices
Dim WithEvents EventSink As SWbemSink
Dim strQuery As String
Private Sub Form_Load()
' Initialize server.
Set Server = CreateObject("WMSServer.Server")
' Create event sink.
Set EventSink = New SWbemSink
' Get services.
Set Services = GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" _
& Server.Name & "\Root\cimv2")
' Set individual queries for each event class that you want to log.
strQuery = "select * from WMS_PublishingPoint_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
strQuery = "select * from WMS_Server_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
strQuery = "select * from WMS_Client_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
strQuery = "select * from WMS_LimitChanged_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
strQuery = "select * from WMS_LimitHit_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
strQuery = "select * from WMS_Plugin_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
strQuery = "select * from WMS_Cache_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
strQuery = "select * from WMS_Playlist_Event"
Services.ExecNotificationQueryAsync EventSink, strQuery
End Sub
Private Sub EventSink_OnObjectReady( _
ByVal objWbemObject As WbemScripting.ISWbemObject, _
ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
' Catch event.
strEventText = objWbemObject.GetObjectText_
End Sub
See Also
Reference
IWMSWMIBridgeAdmin Object (C#)
IWMSWMIBridgeAdmin Object (Visual Basic .NET)