以编程方式创建/删除Windows Media Services发布点

时间:2010-02-19 21:42:32

标签: c# .net windows-media-server windows-media-services

我正在寻找一个.NET包装器,以编程方式通过WMI创建和删除Windows Media Services发布点。

我不可能是唯一一个想通过.NET做到这一点的人,所以在我重新发明轮子之前,有人看过任何代码样本来做这件事吗?

2 个答案:

答案 0 :(得分:0)

在Windows SDK 7.1中有以下文件,可以作为起点。

的Windows \ V7.1 \样品\多媒体\ windowsmediaservices9 \ JScript的\ addPub.js

/*---------------------------------------------------------------------
 Copyright (C) Microsoft Corporation. All rights reserved.
 Script name    : Add Publishing Point (addpub)
 Script version : 1.0
 Description    : This script adds a publishing point to the target
                  server.
 Command line parameters :
           [-s <Server1>] -n <pub1> -t <od|bc> -p <path>
 -s represents target server, -n represents publishing point name,
 -p represents path, -t represent type of publishing point.
 There are 4 Publishing point types.
 od = On-demand, bc = broadcast
 Example : addpub -s server1 -n odpub1 -t od -p c:/wsh1
 Returns  :
 1. Usage: addpub [-s <Server1>] -n <pub1> -t <od|bc> -p <path>
 2. Server %server% is not a valid WMS Server
 3.  %type% is not a valid publishing point type
 OS Requirements       :  Windows Server 2003 (all versions)
 Software requirements :  WMS Server
 Scripting Engine      : Jscript
 ---------------------------------------------------------------------*/
WMS_PUBLISHING_POINT_TYPE_ON_DEMAND = 1;
WMS_PUBLISHING_POINT_TYPE_BROADCAST = 2;

var objServer = null;
var dwWhichArg = 0;
var szEachArg = "";
var szTemp = "";
var szArgServer = "";
var szArgPubPoint = "";
var szArgPubPointType = "";
var szArgPubPointPath = "";
var bCheckName = false;
var bCheckPath = false;
var bCheckType = false;

var objArgs = WScript.Arguments;

if( 0 == WScript.Arguments.length )
{
    DisplayUsage(); 
}

// Parse the command to seperate out the server name and publishing points.

while( dwWhichArg < WScript.Arguments.length )
{
    szEachArg = objArgs( dwWhichArg );
    if( "-s" == szEachArg.toLowerCase() )
    {
        dwWhichArg = dwWhichArg + 1;
        if(dwWhichArg >= WScript.Arguments.length )    //ex: addpub ... -n p1 -s
        {
            DisplayUsage();
        }
        szEachArg = objArgs( dwWhichArg );
        if((szEachArg.toLowerCase()== "-n") || (szEachArg.toLowerCase()== "-p") || (szEachArg.toLowerCase()== "-t"))   //if next szEachArg is -p,-t,-n display usage : since syntax is wrong
        {
            DisplayUsage();
        }
        else
        {
            //accept only one server name
            if(szEachArg.lastIndexOf(",")== -1)
            {
                szArgServer = szEachArg;
            }
            else
            {
                DisplayUsage();
            }
        }
    }
    else if(szEachArg.toLowerCase()== "-n")
    {
        bCheckName = true;
        dwWhichArg = dwWhichArg + 1;

        if(dwWhichArg >=WScript.Arguments.length)    //ex: addpub ... -s s1 -p
        {
            DisplayUsage();
        }
        szEachArg = objArgs(dwWhichArg);
        if((szEachArg.toLowerCase()== "-p") || (szEachArg.toLowerCase()== "-t") || (szEachArg.toLowerCase()== "-s"))  //if next szEachArg is -s,-t,-p display usage : since syntax is wrong
        {
              DisplayUsage();
        }
        else
        {
            //accept only one publishing point name
            if(szEachArg.lastIndexOf(",")== -1)
            {
                szArgPubPoint=szEachArg;
            }
            else
            {
                DisplayUsage();
            }
        }
    }
    else if(szEachArg.toLowerCase()== "-p")
    {
        bCheckPath = true;
        dwWhichArg = dwWhichArg + 1;

        if(dwWhichArg >=WScript.Arguments.length)    //ex: addpub ... -s s1 -p
        {
            DisplayUsage();
        }
        szEachArg = objArgs(dwWhichArg);
        if((szEachArg.toLowerCase()== "-t") || (szEachArg.toLowerCase()== "-s") || (szEachArg.toLowerCase()== "-n"))  //display usage : since syntax is wrong
        {
            DisplayUsage();
        }
        else
        {
            //accept only one path
            if(szEachArg.lastIndexOf(",")== -1)
            {
                szArgPubPointPath=szEachArg;
            }
            else
            {
                DisplayUsage();
            }
        }
    }
    else if(szEachArg.toLowerCase()== "-t")
    {
        bCheckType = true;
        dwWhichArg = dwWhichArg + 1;

        if(dwWhichArg >=WScript.Arguments.length)
        {
            DisplayUsage();
        }
        szEachArg = objArgs(dwWhichArg);
        if((szEachArg.toLowerCase()== "-p") || (szEachArg.toLowerCase()== "-n") || (szEachArg.toLowerCase()== "-s"))  //display usage, since syntax is wrong
        {
            DisplayUsage();
        }
        else
        {
            //accept only one type
            if(szEachArg.lastIndexOf(",")== -1)
            {
                szArgPubPointType=szEachArg;
            }
            else
            {
                DisplayUsage();
            }
        }
    }
    else  // if argument is not -p,-n,-t,-s  i.e. if it is an invalid argument
    {
        DisplayUsage();
    }

    dwWhichArg = dwWhichArg + 1;
}

if( (!bCheckName) || (!bCheckPath) || (!bCheckType) )       //Ex:  compulsory part -p,-t or -n is missing.
{
    DisplayUsage();
}

// Connect to Server
//if server name is not mentioned, then start Publishing points on localhost
if( "" == szArgServer )
{
    szArgServer = "LocalHost";
}

var bFailed;
bFailed = false;

try
{
    objServer = new ActiveXObject( "WMSServer.server", szArgServer );
}
catch(e)
{
    bFailed = true;
    szTemp = "Server '" + szArgServer + "' is not a valid WMS Server \n";
    Trace( szTemp );
}

if( !bFailed )
{
    Trace("\nAdding Publishing Points at "+ szArgServer );

    //Add Publishing Point
    AddPublishingPoint();
}


// This function checks if the publishing point name and type are valid, and then
// adds it to server.
function AddPublishingPoint()
{
    var bFailed, nType;
    bFailed = false;

    //check if the type is a valid type
    switch(szArgPubPointType)
    {
        case 'od' :
            nType = WMS_PUBLISHING_POINT_TYPE_ON_DEMAND;
            break;
        case 'bc' :
            nType = WMS_PUBLISHING_POINT_TYPE_BROADCAST;
            break;
        default :
        {
            bFailed = true;
            szTemp = "Adding Publishing Point '" + szArgPubPoint + "' failed: Unknown type\n";
            break;
        }
    }

    if( !bFailed )
    {
        try
        {
            var objPubPoint = objServer.PublishingPoints.Add( szArgPubPoint, nType, szArgPubPointPath );
            szTemp = "Added " + szArgPubPoint;
        }
        catch(e)
        {
            var errorcode = e.number >>> 0;
            szTemp = "Error Code 0x" + errorcode.toString(16) + ": " + e.description;
        }
    }

    Trace( szTemp );
}

function DisplayUsage()
{
    Trace( "Usage: addpub [-s <Server1>] -n <pub1> -t <od|bc> -p <path>" );
    WScript.Quit(1);
}

function Trace(Msg)
{
    WScript.Echo(Msg);
}

答案 1 :(得分:0)

我正在使用记录在案here的媒体服务9 SDK。 SDK与运行时组件捆绑在一起,因此您需要在安装了运行时的Windows Server计算机上复制Microsoft.WindowsMediaServices.Interop.dllWMSServerTypeLib.dll。我在C:\Windows\System32\windows media\server找到了他们。然后,注册类型库并添加对Interop程序集的引用。

然后,使用SDK:

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

// instantiating the server for a remote host
Type serverType = Type.GetTypeFromProgID("WMSServer.Server", "MediaServer");

// may need to wrap this in an impersonation context depending the server's ACL
WMSServer server = (WMSServer)Activator.CreateInstance(serverType); 

// removing all of the publish points
for(int i = server.PublishingPoints.Count - 1; i >= 0; i--)
{
   server.PublishingPoints.Remove(i);
}

// adding a push broadcast point
IWMSBroadcastPublishingPoint newPoint = 
          (IWMSBroadcastPublishingPoint) server.PublishingPoints.Add(
             "NewPoint", WMS_PUBLISHING_POINT_CATEGORY.WMS_PUBLISHING_POINT_BROADCAST,
              "Push:*");

// cloning
IWMSPublishingPoint cloned = server.PublishingPoints.Clone("Cloned", newPoint);

我包含克隆,因为我在尝试在远程计算机上添加新发布点时遇到错误(The stub received bad data)。我看到另一个线程,其中有人有同样的问题,所以我想而不是打架它,我只是创建一个模板发布点,并创建所有新点作为克隆。