다음을 통해 공유


Configuring System Plug-ins

Plug-ins provide much of the functionality for a Windows Media server. In addition to the system plug-ins included with Windows Media Services, any number of specialized custom plug-ins can be created for use with the server. Many of the system plug-ins expose an administration interface that you can use to modify and configure the plug-in programmatically. If you create your own plug-in, you can also expose a custom administration interface. For more information about the system plug-ins that expose user interfaces, see Programming System Plug-in Properties. For more information about creating an administration interface for your custom plug-in, see Creating an MMC Property Page. In the following examples, the WMS IP Address Authorization plug-in included with Windows Media Services is configured by using its administration interface.

Note

   To use the C++ system plug-in interfaces, the following line must appear in your code exactly as shown, or the interfaces will not be properly defined. When this import statement is used, it is not necessary to include a reference to the file "WMSServer.h."

  •                                raw_interfaces_only
    

Visual Basic .NET Example

Imports Microsoft.WindowsMediaServices.Interop
Imports System.Runtime.InteropServices

' Declare variables.
Dim Server As WMSServer
Dim Plugin As IWMSPlugin
Dim IPAdmin As IWMSIPAdmin
Dim Address As String
Dim Mask As String
Dim i As Integer

Try

    ' Create the WMSServer object.
    Server = New WMSServer()

    ' Retrieve the plug-in to be configured.
    Plugin = Server.EventHandlers.Item("WMS IP Address Authorization")

    ' Retrieve the custom interface of the plug-in.
    IPAdmin = Plugin.CustomInterface

    ' Configure the plug-in to allow all IP addresses
    ' except those specifically set to be denied.
    IPAdmin.AccessListOptions = WMS_IP_ACCESS_OPTIONS.WMS_IP_ACCESS_ALLOW_BY_DEFAULT

    ' Add an IP to the list of banned addresses.
    ' Setting the mask in this case bans all IPs
    ' in the range of 128.117.93.*
    IPAdmin.DisallowIP.Add("128.117.93.5", "255.255.255.0")

    ' Retrieve the information associated
    ' with each banned address.
    For i = 0 To IPAdmin.DisallowIP.Count - 1
        Address = IPAdmin.DisallowIP.Item(i).Address
        Mask = IPAdmin.DisallowIP.Item(i).Mask
    Next

Catch errCom As COMException
    ' TODO: Handle COM exceptions.
Catch err As Exception
    ' TODO: Exception handler goes here.

Finally
    ' TODO: Clean-up code goes here.
End Try

C# Example

using Microsoft.WindowsMediaServices.Interop;
using System.Runtime.InteropServices;

WMSServer Server;
IWMSPlugin Plugin;
IWMSPlugins Plugins;
IWMSIPAdmin IPAdmin;
string Address = "";
string Mask = "";
int i;

try
{
    Server = new WMSServerClass();

    // Retrieve the plug-in to be configured.
    Plugins = Server.EventHandlers;
    for (i = 0; i< Plugins.Count; i++)
    {
        if ("WMS IP Address Authorization" == Plugins[i].Name)
        {
            Plugin = Plugins[i];

            // Retrieve the custom interface of the plug-in.
            IPAdmin = (IWMSIPAdmin)Plugin.CustomInterface;

            // Configure the plug-in to allow all IP addresses
            // except those specifically set to be denied.
            IPAdmin.AccessListOptions = WMS_IP_ACCESS_OPTIONS.WMS_IP_ACCESS_ALLOW_BY_DEFAULT;

            // Add an IP to the list of banned addresses.
            // Setting the mask in this case bans all IPs
            // in the range of 128.117.93.*
            IPAdmin.DisallowIP.Add("128.117.93.5", "255.255.255.0");

            // Retrieve the information associated
            // with each banned address.
            for (i = 0; i < IPAdmin.DisallowIP.Count; i++)
            {
                Address = IPAdmin.DisallowIP[i].Address;
                Mask = IPAdmin.DisallowIP[i].Mask;
            }

            break;
        }
    }
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception exc)
{
    // TODO: Exception handler goes here.
}
finally
{
    // TODO: Clean-up code goes here.
}

C++ Example

#include <windows.h>
#include <atlbase.h>    // Includes CComBSTR and CComVariant.

// To access system plug-in interfaces, the
// entire type library must be imported as shown.
#import "WMSServerTypeLib.dll" no_namespace named_guids \
                               raw_interfaces_only

// Declare variables and interfaces.
IWMSServer      *pServer;
IWMSPlugins     *pPlugins;
IWMSPlugin      *pPlugin;
IDispatch       *pDispatch;
IWMSIPAdmin     *pIPAdmin;
IWMSIPList      *pIPList;
IWMSIPEntry     *pIPEntry;

HRESULT         hr;
CComVariant     varIndex;
CComBSTR        bstrIP;
CComBSTR        bstrMask;
long            lCount;

// 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 event handler plug-ins.
hr = pServer->get_EventHandlers(&pPlugins);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to an IWMSPlugin interface
// of the plug-in to be configured.
varIndex = "WMS IP Address Authorization";
hr = pPlugins->get_Item(varIndex, &pPlugin);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the custom interface
// of the plug-in.
hr = pPlugin->get_CustomInterface(&pDispatch);
if (FAILED(hr)) goto EXIT;

// Query the specific administration interface
// for the plug-in.
hr = pDispatch->QueryInterface(IID_IWMSIPAdmin,
                              (void **)&pIPAdmin);
if (FAILED(hr)) goto EXIT;

// Configure the plug-in to allow all IP addresses
// except those specifically set to be denied.
hr = pIPAdmin->put_AccessListOptions(WMS_IP_ACCESS_ALLOW_BY_DEFAULT);
if (FAILED(hr)) goto EXIT;

// Retrieve the list of banned IP addresses.
hr = pIPAdmin->get_DisallowIP(&pIPList);
if (FAILED(hr)) goto EXIT;

// Add an IP to the list of banned addresses.
// Setting the mask in this case bans all IPs
// in the range of 128.117.93.*
bstrIP = "128.117.93.5";
bstrMask = "255.255.255.0";
hr = pIPList->Add(bstrIP, bstrMask, &pIPEntry);
if (FAILED(hr)) goto EXIT;

// Retrieve the total count of banned IPs.
hr = pIPList->get_Count(&lCount);
if (FAILED(hr)) goto EXIT;

// Retrieve the information associated
// with each banned address.
for (x = 0; x < lCount; x++)
{
    varIndex = x;
    hr = pIPList->get_Item(varIndex, &pIPEntry);
    if (FAILED(hr)) goto EXIT;

    hr = pIPEntry->get_Address(&bstrIP);
    if (FAILED(hr)) goto EXIT;
    hr = pIPEntry->get_Mask(&bstrMask);
    if (FAILED(hr)) goto EXIT;

    // Release the IWMSIPEntry object.
    pIPEntry->Release();
}

EXIT:
    // TODO: Release temporary COM objects and uninitialize COM.

See Also (General)

See Also (Visual Basic .NET)

See Also (C#)

See Also (C++)