在 Configuration Manager中,可以使用 和 SMS_Program 类和类属性列出所有程序及其最大运行时值SMS_Package。
列出所有程序及其最大运行时间
- 设置与 SMS 提供程序的连接。 
- 使用 - SMS_Package类加载可用包。
- 使用 - SMS_Program类和- PackageID每个包中的 属性枚举每个程序集。
- 输出每个程序的包名称、程序名称和最大运行时间值。 
示例
以下示例方法演示如何使用相应的包名称、程序名称和最大运行时间列出所有程序。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
Sub ListPackagesProgramsandMaximumRunTimeValue(connection)
    Const wbemFlagReturnImmediately = 16    Const wbemFlagForwardOnly = 32    Dim packageQuery    Dim allPackages    Dim package    Dim packageID    Dim program    Dim programsForPackage
    ' Build query to get all of the packages.
    packageQuery = "SELECT * FROM SMS_Package"
    ' Run query.
    Set allPackages = connection.ExecQuery(packageQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)
    ' The query returns a collection of package objects that needs to be enumerated.
    For Each package In allPackages
        ' Output package name and get the PackageID value to use in program query.
        WScript.Echo ""
        WScript.Echo "Package: "  & package.Name
        packageID = package.PackageID
        ' Build query to get the programs for the package.
        packageQuery = "SELECT * FROM SMS_Program WHERE PackageID='" & packageID & "'"
        ' Run query.
        Set programsForPackage = connection.ExecQuery(packageQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)
        ' The query returns a collection of program objects that needs to be enumerated.
        For Each program In programsForPackage
            ' Output Maximum Runtime Value for each program found.
            WScript.Echo "  Program: "  & program.ProgramName
            WScript.Echo "  Maximum Runtime Value: "  & program.Duration
        Next
    Next
End Sub
public void ListPackagesProgramsandMaximumRunTimeValue(WqlConnectionManager connection)
{
    try
    {
        // Build query to get the packages.
        string packageQuery = "SELECT * FROM SMS_Package";
        // Load the specific program to change (programname is a key value and must be unique).
        IResultObject allPackages = connection.QueryProcessor.ExecuteQuery(packageQuery);
        // The query returns a collection of packages that needs to be enumerated.
        foreach(IResultObject package in allPackages)
        {
            // Output package name and get the PackageID value to use in program query.
            Console.WriteLine();
            Console.WriteLine("Package: "  + package["Name"].StringValue);
            string packageID = package["PackageID"].StringValue;
            // Build query to get the programs for the package.
            string programQuery = "SELECT * FROM SMS_Program WHERE PackageID='" + packageID + "'";
            // Load the all programs belonging to the package.
            IResultObject programsForPackage = connection.QueryProcessor.ExecuteQuery(programQuery);
            // The query returns a collection of programs that needs to be enumerated.
            foreach(IResultObject program in programsForPackage)
            {
                // Output Maximum Runtime Value for each program found.
                Console.WriteLine("   Program: "  + program["ProgramName"].StringValue);
                Console.WriteLine("   Maximum Runtime Value: "  + program["Duration"].IntegerValue);
            }
        }
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to list the packages and programs. Error: " + ex.Message);
        throw;
    }
}
示例方法具有以下参数:
| 参数 | 类型 | 说明 | 
|---|---|---|
| connection | -管理: WqlConnectionManager- VBScript: SWbemServices | 与 SMS 提供程序的有效连接。 | 
编译代码
C# 示例需要:
命名空间
系统警报
Microsoft。ConfigurationManagement.ManagementProvider
Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
可靠编程
有关错误处理的详细信息,请参阅关于Configuration Manager错误。