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

发布于 2024-08-22 14:49:54 字数 136 浏览 0 评论 0原文

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

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

I'm looking for a .NET wrapper to programmatically Create and Delete Windows Media Services publishing points through WMI.

I can't be the only one to ever want to do this through .NET, so before I re-invent the wheel, anyone seen any code samples out there to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写给空气的情书 2024-08-29 14:49:54

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

Windows\v7.1\Samples\multimedia\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);
}

In the windows SDK 7.1 there is the following file, could be a starting point.

Windows\v7.1\Samples\multimedia\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);
}
许一世地老天荒 2024-08-29 14:49:54

我正在使用媒体服务 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);

我包含了克隆,因为在尝试在远程计算机上添加新的发布点时遇到错误(存根收到错误数据)。我看到另一个线程中有人遇​​到了同样的问题,所以我想与其与之抗争,不如创建一个模板发布点并将所有新点创建为该点的克隆。

I'm using the Media Services 9 SDK which is documented here. The SDK is bundled with the runtime components, so you'll need to copy Microsoft.WindowsMediaServices.Interop.dll and WMSServerTypeLib.dll from your Windows Server machine with the runtime installed. I found them at C:\Windows\System32\windows media\server. Then, register the type library and add a reference to the Interop assembly.

Then, to use the 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);

I included cloning because I encountered an error (The stub received bad data) when trying to add a new publishing point on a remote machine. I saw another thread where someone had the same issue, so I figured instead of fighting it, I would just create a template publishing point and create all of the new points as clones of that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文