如何将 Txtsetup.oem 文件描述的 Windows 驱动程序导入Configuration Manager

可以在 Configuration Manager 中使用类SMS_Driver中的 CreateFromOEM 方法导入由 Txtsetup.oem 文件描述的 Windows 驱动程序。 Configuration Manager可以从 .inf 文件自动为大多数驱动程序创建定义。 但是,在 Windows Vista 之前的操作系统上安装大容量存储驱动程序时,Configuration Manager还必须包含 Txtsetup.oem 文件中的一些信息。 为此, CreateFromOEM 请为 Txtsetup.oem 文件中引用的每个 .inf 文件创建 SMS_Driver服务器 WMI 类 对象。 然后,你有机会在保存驱动程序属性之前自定义这些属性。

注意

如果驱动程序制造商提供了 Txtsetup.oem 文件,则如果你计划部署 Windows 2000、Windows XP 或 Windows Server 2003,则应使用此过程而不是 .inf 文件导入驱动程序。

导入 Windows 驱动程序

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

  2. 调用 SMS_DriverCreateFromOEM 方法以获取管理基对象的集合。

  3. 对于管理基对象,请为每个驱动程序创建一个 SMS_Driver 对象。

  4. 填充 SMS_Driver 对象。

  5. 提交 SMS_Driver 对象。

示例

以下示例方法使用提供的路径和 Txtsetup.oem 文件名为 Windows 驱动程序创建 一个 SMS_Driver 对象。 该示例还通过将 IsEnabled 属性的值设置为 来 true启用驱动程序。 帮助程序函数 GetDriverName 用于从驱动程序包 XML 获取驱动程序的名称。

注意

参数 path 必须作为通用命名约定 (UNC) 网络路径提供,例如 \\localhost\Drivers\VMSCSI\。

在此示例中,属性 LocaleID 硬编码为英语 (美国) 。 如果需要非美国区域设置。安装,可以从 SMS_Identification 服务器 WMI 类LocaleID 属性获取它。

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

Sub ImportOemDriver(connection,path,name)  

    Dim inParams  
    Dim outParams  
    Dim driver  
    Dim driverClass  

    On Error Resume Next  

    Set driverClass = connection.Get("SMS_Driver")  

    Set inParams = driverClass.Methods_("CreateFromOEM").inParameters.SpawnInstance_()  

    ' Set the driver path and INF file.  
    inParams.Properties_.item("DriverPath") = path  
    inParams.Properties_.item("OEMFile") = name  

    ' Execute the method.  
        Set outParams = driverClass.ExecMethod_("CreateFromOEM", inParams)      

    If Err <> 0 Then  
        Wscript.Echo "Failed to import driver: " + path +"\" + name   
        Exit Sub  
    End If      

    For Each driver In outParams.Drivers  
        ' Set driver name and enable the driver.  
        Dim LocalizedSettings  
        LocalizedSettings = array(0)  

        Set  LocalizedSettings(0) = connection.Get("SMS_CI_LocalizedProperties").SpawnInstance_()  
        LocalizedSettings(0).Properties_.item("LocaleID") = 1033  
        LocalizedSettings(0).Properties_.item("DisplayName") = _  
               GetDriverName(driver.Properties_.item("SDMPackageXML"), "//DisplayName", "Text")  
        LocalizedSettings(0).Properties_.item("Description") = ""          
        driver.Properties_.item("LocalizedInformation") = LocalizedSettings  
        driver.Properties_.item("IsEnabled") = true  
        driver.Put_   
    Next              
End Sub  

Function GetDriverName(xmlContent, nodeName, attributeName)  
    ' Load the XML Document  
    Dim attrValue  
    Dim XMLDoc  
    Dim objNode  
    Dim displayNameNode  

    attrValue = ""  
    Set XMLDoc = CreateObject("Microsoft.XMLDOM")       
    XMLDoc.async = False  
    XMLDoc.loadXML(xmlContent)  

    'Check for a successful load of the XML Document.  
    If xmlDoc.parseError.errorCode <> 0 Then  
        WScript.Echo vbcrlf & "Error loading XML Document. Error Code : 0x" & hex(xmldoc.parseerror.errorcode)  
        WScript.Echo "Reason: " & xmldoc.parseerror.reason  
        WScript.Echo "Parse Error line " & xmldoc.parseError.line & ", character " & _  
                      xmldoc.parseError.linePos & vbCrLf & xmldoc.parseError.srcText  

        GetXMLAttributeValue = ""          
    Else  
        ' Select the node  
        Set objNode = xmlDoc.SelectSingleNode(nodeName)  

        If Not objNode Is Nothing Then  
            ' Found the element, now just pick up the Text attribute value  
            Set displayNameNode = objNode.attributes.getNamedItem(attributeName)  
            If Not displayNameNode Is Nothing Then  
               attrValue = displayNameNode.value  
            Else  
               WScript.Echo "Attribute not found"  
            End If  
        Else  
            WScript.Echo "Failed to locate " & nodeName & " element."  
        End If  
    End If  

    ' Save the results  
    GetDriverName = attrValue  
End Function  
public void ImportOemDriver(  
WqlConnectionManager connection,  
string path,  
string name)  
{  
    try  
    {  
        Dictionary<string, object> inParams = new Dictionary<string, object>();  

        // Set up parameters for the path and file name.  
        inParams.Add("DriverPath", path);  
        inParams.Add("OEMFile", name);  

        // Import the INF file.  
        IResultObject outParams = connection.ExecuteMethod("SMS_Driver", "CreateFromOEM", inParams);  

        // Create the driver instance from the management base object returned in result["Drivers"].  

        foreach (object obj in outParams["Drivers"].ObjectArrayValue)  
        {  
            IResultObject driver = connection.CreateInstance(obj);  
            driver["IsEnabled"].BooleanValue = true;  

            List<IResultObject> driverInformationList = driver.GetArrayItems("LocalizedInformation");  

            // Set up the display name and other information.  
            IResultObject driverInfo = connection.CreateEmbeddedObjectInstance("SMS_CI_LocalizedProperties");  
            driverInfo["DisplayName"].StringValue = GetDriverName(driver);  
            driverInfo["LocaleID"].IntegerValue = 1033;  
            driverInfo["Description"].StringValue = "";  

            driverInformationList.Add(driverInfo);  

            driver.SetArrayItems("LocalizedInformation", driverInformationList);  

            // Commit the SMS_Driver object.  
            driver.Put();  
        }  
    }  
    catch (SmsException e)  
    {  
        Console.WriteLine("Failed to import driver: " + e.Message);  
        throw;  
    }  
}  
public string GetDriverName(IResultObject driver)          
{  
    // Extract   
    XmlDocument sdmpackage = new XmlDocument();  

    sdmpackage.LoadXml(driver.Properties["SDMPackageXML"].StringValue);  

    // Iterate over all the <DisplayName/> tags.  
    foreach (XmlNode displayName in sdmpackage.GetElementsByTagName("DisplayName"))           
    {                  
    // Grab the first one with a Text attribute not equal to null.  
        if (displayName != null && displayName.Attributes["Text"] != null    
            && !string.IsNullOrEmpty(displayName.Attributes["Text"].Value))    
        {                        
                // Return the DisplayName text.  
                return displayName.Attributes["Text"].Value;      
        }              
    }   
    //  Default the driverName to the UniqueID.  
    return driver["CI_UniqueID"].StringValue;         
 }  

示例方法具有以下参数:

参数 类型 说明
Connection -管理: WqlConnectionManager
- VBScript: SWbemServices
与 SMS 提供程序的有效连接。
path -管理: String
- VBScript: String
包含驱动程序内容的文件夹的有效 UNC 网络路径。 例如,\\Servers\Driver\VideoDriver。
name -管理: String
- VBScript: String
Txtsetup.oem 文件的名称。 例如,你可能有 \\server\drivers\Video for 和 Txtsetup.oem path for name

编译代码

此 C# 示例需要:

命名空间

System

System.Collections.Generic

System.Text

Microsoft。ConfigurationManagement.ManagementProvider

Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

可靠编程

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

.NET Framework 安全性

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

另请参阅

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