如何为驱动程序指定受支持的平台

在 Configuration Manager 中,可以在驱动程序的 SMS_Driver 服务器 WMI 类对象的属性 XML 中SDMPackageXML指定驱动程序支持的平台。 XML 包含一个节点 PlatformApplicabilityConditions ,可为其添加 PlatformApplicabilityCondition 驱动程序支持的每个平台的元素。

注意

应仅添加 SMS_SupportedPlatforms服务器 WMI 类 对象中列出的平台。 驱动程序只能针对主要作系统版本进行条件,也就是说,无法在 Service Pack 中以驱动程序为目标。

警告

支持的平台部分 SDMPackageXML 是 CI-XML 架构中唯一可以编辑的部分。 不应对 XML 的其他部分进行更改。

以下 XML 演示了支持两个平台的驱动程序。 有关支持的平台架构的详细信息,请参阅 作系统部署驱动程序支持的平台架构

<PlatformApplicabilityConditions>
    <PlatformApplicabilityCondition DisplayName="All x64 Windows XP Professional" MaxVersion="5.20.9999.9999" MinVersion="5.20.3790.0" Name="Win NT" Platform="x64">
        <Query1>SELECT * FROM Win32_OperatingSystem WHERE BuildNumber = '3790' AND OSType=18 AND ProductType=1</Query1>
        <Query2>SELECT * FROM Win32_Processor WHERE Architecture=9 AND DataWidth=64</Query2>
        </PlatformApplicabilityCondition>
    <PlatformApplicabilityCondition DisplayName="All x86 Windows 2000" MaxVersion="5.00.9999.9999" MinVersion="5.00.0000.0" Name="Win NT" Platform="I386">
        <Query1>SELECT * FROM Win32_OperatingSystem WHERE BuildNumber = '2195' AND OSType=18 AND ServicePackMajorVersion >= 4</Query1>
        <Query2>SELECT * FROM Win32_Processor WHERE Architecture=0</Query2>
    </PlatformApplicabilityCondition>
</PlatformApplicabilityConditions>

若要验证平台适用性要求,请使用所需平台的 SMS_SupportedPlatforms 服务器 WMI 类Condition 属性。

指定驱动程序支持的平台

  1. 设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识

  2. 获取驱动程序的 SMS_Driver 服务器 WMI 类 对象。 驱动程序由键属性 CI_ID标识。 有关使用键属性获取对象的信息,请参阅如何使用托管代码读取Configuration Manager对象

  3. 更新驱动程序 XML。

  4. 将更改提交回 SMS 提供程序。

示例

以下示例方法将受支持的平台添加到由 objDriver标识的驱动程序。 例如,以下调用代码将 Windows XP Professional x64作系统添加到受支持平台的驱动程序 objDriver 列表中。 可以从其 SMS_SupportedPlatforms 对象实例获取特定平台的详细信息。

AddSupportedPlatform objDriver, "All x64 Windows XP Professional", "5.20.9999.9999","5.20.3790.0", "Win NT","x64", "SELECT * FROM Win32_OperatingSystem WHERE BuildNumber = 3790 AND OSType=18 AND ProductType=1", "SELECT * FROM Win32_Processor WHERE Architecture=9 AND DataWidth=64"

有关调用示例代码的信息,请参阅调用Configuration Manager代码片段

Sub AddSupportedPlatform( objDriver, sDisplayName, sMaxVersion, sMinVersion, sName, sPlatform, sQuery1, sQuery2 )

    Dim xmlDoc
    Dim objPlatformNode
    Dim objAttr
    Dim objQuery1Node
    Dim objQuery2Node
    Dim objPlatformsNode
    Dim objDriverNode

    ' Load the SDM Package XML.
    Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")

    xmlDoc.async = False
    xmlDoc.loadXML(objDriver.Properties_.item("SDMPackageXML"))
    xmlDoc.setProperty _
     "SelectionNamespaces","xmlns:dcm='http://schemas.microsoft.com/SystemsCenterConfigurationManager/2006/03/24/DesiredConfiguration'"

    ' Create a new platform node.
    Set objPlatformNode = xmlDoc.createNode _
    ( 1, "PlatformApplicabilityCondition", _
     "http://schemas.microsoft.com/SystemsCenterConfigurationManager/2006/03/24/DesiredConfiguration")

    ' Set DisplayName.
    Set objAttr = xmlDoc.createAttribute("DisplayName")
    objAttr.value = sDisplayName
    objPlatformNode.setAttributeNode(objAttr)

    ' Set MaxVersion.
    Set objAttr = xmlDoc.createAttribute("MaxVersion")
    objAttr.value = sMaxVersion
    objPlatformNode.setAttributeNode(objAttr)

    ' Set MinVersion.
    Set objAttr = xmlDoc.createAttribute("MinVersion")
    objAttr.value = sMinVersion
    objPlatformNode.setAttributeNode(objAttr)

    ' Set Name.
    Set objAttr = xmlDoc.createAttribute("Name")
    objAttr.value = sName
    objPlatformNode.setAttributeNode(objAttr)

    ' Set Platform.
    Set objAttr = xmlDoc.createAttribute("Platform")
    objAttr.value = sPlatform
    objPlatformNode.setAttributeNode(objAttr)

    ' Set Query1.
    Set objQuery1Node = xmlDoc.createNode(1, "Query1", "http://schemas.microsoft.com/SystemsCenterConfigurationManager/2006/03/24/DesiredConfiguration")
    objQuery1Node.text = sQuery1
    objPlatformNode.appendChild(objQuery1Node)

    ' Set Query2.
    Set objQuery2Node = xmlDoc.createNode(1, "Query2", "http://schemas.microsoft.com/SystemsCenterConfigurationManager/2006/03/24/DesiredConfiguration")
    objQuery2Node.text = sQuery2
    objPlatformNode.appendChild(objQuery2Node)

    ' Append to platforms node.
    Set objPlatformsNode = xmlDoc.selectSingleNode("/dcm:DesiredConfigurationDigest/dcm:Driver/dcm:PlatformApplicabilityConditions")
    objPlatformsNode.appendChild(objPlatformNode)

    ' Increment the version number.
    Set objDriverNode = xmlDoc.selectSingleNode("/dcm:DesiredConfigurationDigest/dcm:Driver")
    Set objAttr = objDriverNode.attributes.getNamedItem("Version")
    objAttr.value = objAttr.value + 1

    ' Save the object.
    objDriver.Properties_.item("SDMPackageXML") = xmlDoc.xml
    objDriver.Put_

End Sub
public void AddSupportedPlatform(
    IResultObject driver,
    string displayName,
    string maxVersion,
    string minVersion,
    string name,
    string platform,
    string query1,
    string query2)
{
    try
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(driver["SDMPackageXML"].StringValue);

        string dcmXmlNamespace = "http://schemas.microsoft.com/SystemsCenterConfigurationManager/2006/03/24/DesiredConfiguration";
        XmlNode condition = xmlDoc.CreateNode
         (XmlNodeType.Element, "PlatformApplicabilityCondition", dcmXmlNamespace);

        XmlAttribute displayNameAttribute = xmlDoc.CreateAttribute("DisplayName");
        displayNameAttribute.Value = displayName;
        condition.Attributes.SetNamedItem(displayNameAttribute);

        XmlAttribute osMaxVersionAttribute = xmlDoc.CreateAttribute("MaxVersion");
        osMaxVersionAttribute.Value = maxVersion;
        condition.Attributes.SetNamedItem(osMaxVersionAttribute);

        XmlAttribute osMinVersionAttribute = xmlDoc.CreateAttribute("MinVersion");
        osMinVersionAttribute.Value = minVersion;
        condition.Attributes.SetNamedItem(osMinVersionAttribute);

        XmlAttribute osNameAttribute = xmlDoc.CreateAttribute("Name");
        osNameAttribute.Value = name;
        condition.Attributes.SetNamedItem(osNameAttribute);

        XmlAttribute osPlatformAttribute = xmlDoc.CreateAttribute("Platform");
        osPlatformAttribute.Value = platform;
        condition.Attributes.SetNamedItem(osPlatformAttribute);

        // Create <Query1/> and <Query2/> child nodes.
        // Then attach to <PlatformApplicabilityCondition/>.
        XmlNode query1Node = xmlDoc.CreateNode
            (XmlNodeType.Element, "Query1", dcmXmlNamespace);
        query1Node.InnerText = query1;
        condition.AppendChild(query1Node);

        XmlNode query2Node = xmlDoc.CreateNode
            (XmlNodeType.Element, "Query2", dcmXmlNamespace);
        query2Node.InnerText = query2;
        condition.AppendChild(query2Node);

        XmlNode platformsNode = xmlDoc["DesiredConfigurationDigest"]["Driver"]["PlatformApplicabilityConditions"];

         if (platformsNode == null)
        {
            Console.WriteLine("empty");
        }

        platformsNode.AppendChild(condition);

        XmlNode driverNode = xmlDoc["DesiredConfigurationDigest"]["Driver"];
        if (driverNode != null)
        {
            int driverVersion = int.Parse(driverNode.Attributes.GetNamedItem("Version").Value) + 1;
            driverNode.Attributes.GetNamedItem("Version").Value = (driverVersion + 1).ToString();
        }
        else
        {
            throw new XmlException("Unable to find <Driver/> node while AddingSupportedPlatforms");
        }

        // Add the package XML to the driver.
        StringBuilder xmlText = new StringBuilder();
        xmlDoc.WriteContentTo(new XmlTextWriter(new StringWriter(xmlText)));
        driver["SDMPackageXML"].StringValue = xmlText.ToString();

       driver.Put();
    }
    catch (SmsException e)
    {
        Console.WriteLine("failed to add supported platform to driver " + e.Message);
        throw;
    }
}

示例方法具有以下参数:

参数 类型 说明
driver

objDriver
-管理: IResultObject
- VBScript: SWbemObject
- 有效的 SMS_Driver 对象。 有关详细信息,请参阅如何将 INF 文件描述的 Windows 驱动程序导入Configuration Manager
displayName

sDisplayName
-管理: String
- VBScript: String
Configuration Manager控制台中显示的条件的显示名称。
maxVersion

sMaxVersion
-管理: String
- VBScript: String
支持的最大版本。
minVersion

sMinVersion
-管理: String
- VBScript: String
支持的最低版本。
name

sName
-管理: String
- VBScript: String
作系统名称。
platform

sPlatform
-管理: String
- VBScript: String
平台名称。
query1

sQuery1
-管理: String
- VBScript: String
用于标识客户端平台的第一个查询。
query2

sQuery2
-管理: String
- VBScript: String
用于标识客户端平台的第二个查询。

编译代码

此 C# 示例需要:

命名空间

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

System.Xml

System.IO

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

.NET Framework 安全性

有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理

另请参阅

SMS_SupportedPlatforms服务器 WMI 类对象概述如何使用托管代码连接到 Configuration Manager 中的 SMS提供程序如何使用 WMI 连接到Configuration Manager中的 SMS 提供程序如何将步骤移动到其他作系统部署任务序列组如何创建作系统部署任务序列组如何从作系统部署组中删除步骤任务序列概述SMS_SupportedPlatforms服务器 WMI 类