Comment importer un pilote Windows décrit par un fichier Txtsetup.oem dans Configuration Manager

Vous pouvez importer un pilote Windows décrit par un fichier Txtsetup.oem, dans Configuration Manager, à l’aide de la méthode CreateFromOEM dans class SMS_Driver. Configuration Manager pouvez créer automatiquement des définitions pour la plupart des pilotes à partir d’un fichier .inf. Toutefois, lorsque vous installez des pilotes de stockage de masse sur des systèmes d’exploitation antérieurs à Windows Vista, Configuration Manager devez également disposer d’informations contenues dans le fichier Txtsetup.oem. Pour faciliter cela, CreateFromOEM crée des objets de classe WMI SMS_Driver Server pour chaque fichier .inf référencé dans le fichier Txtsetup.oem. Vous avez ensuite la possibilité de personnaliser les propriétés du pilote avant de les enregistrer.

Remarque

Si un fabricant de pilotes a fourni un fichier Txtsetup.oem, vous devez importer le pilote à l’aide de cette procédure au lieu des fichiers .inf si vous envisagez de déployer Windows 2000, Windows XP ou Windows Server 2003.

Pour importer un pilote Windows

  1. Configurez une connexion au fournisseur SMS. Pour plus d’informations, consultez Notions de base du fournisseur SMS.

  2. Appelez la méthode CreateFromOEM de la classe SMS_Driver pour obtenir une collection d’objets de base de gestion.

  3. Pour les objets de base de gestion, créez un objet SMS_Driver pour chaque pilote.

  4. Remplissez l’objet SMS_Driver.

  5. Validez l’objet SMS_Driver.

Exemple

L’exemple de méthode suivant crée un objet SMS_Driver pour un pilote Windows en utilisant le chemin d’accès et le nom de fichier Txtsetup.oem fournis. L’exemple active également le pilote en définissant la valeur de la propriété IsEnabled sur true. La fonction GetDriverName d’assistance est utilisée pour obtenir le nom du pilote à partir du fichier XML du package de pilotes.

Remarque

Le path paramètre doit être fourni sous la forme d’un chemin réseau UNC (Universal Naming Convention), par exemple, \\localhost\Drivers\VMSCSI\.

Dans l’exemple, la LocaleID propriété est codée en dur en anglais (États-Unis). Si vous avez besoin des paramètres régionaux pour les non-États-Unis vous pouvez l’obtenir à partir de la propriété classe LocaleIDWMI du serveur SMS_Identification.

Pour plus d’informations sur l’appel de l’exemple de code, consultez Appel d’extraits de code 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;         
 }  

L’exemple de méthode a les paramètres suivants :

Paramètre Type Description
Connection -Géré: WqlConnectionManager
- VBScript : SWbemServices
Connexion valide au fournisseur SMS.
path -Géré: String
-Vbscript: String
Chemin réseau UNC valide vers le dossier qui contient le contenu du pilote. Par exemple, \\Servers\Driver\VideoDriver.
name -Géré: String
-Vbscript: String
Nom du fichier Txtsetup.oem. Par exemple, vous pouvez avoir \\server\drivers\Video pour path et Txtsetup.oem pour name.

Compilation du code

Cet exemple C# nécessite :

Espaces de noms

Système

System.Collections.Generic

System.Text

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Programmation robuste

Pour plus d’informations sur la gestion des erreurs, consultez À propos des erreurs Configuration Manager.

Sécurité de .NET Framework

Pour plus d’informations sur la sécurisation des applications Configuration Manager, consultez Configuration Manager’administration basée sur les rôles.

Voir aussi

Comment spécifier les plateformes prises en charge pour un pilote