다음을 통해 공유


INF 파일에서 설명한 Windows 드라이버를 Configuration Manager 가져오는 방법

클래스 SMS_Driver CreateFromINF 메서드를 사용하여 Configuration Manager 정보(.inf) 파일로 설명된 Windows 드라이버를 가져올 수 있습니다.

Windows 드라이버를 가져오려면

  1. SMS 공급자에 대한 연결을 설정합니다. 자세한 내용은 SMS 공급자 기본 사항을 참조하세요.

  2. 클래스 SMS_Driver CreateFromINF 메서드를 호출하여 초기 SMS_Driver 서버 WMI 클래스 관리 기본 개체를 가져옵니다.

  3. 관리 기본 개체를 사용하여 SMS_Driver 인스턴스를 만듭니다.

  4. 개체를 채웁 수 있습니다 SMS_Driver .

  5. 개체를 SMS_Driver 커밋합니다.

예시

다음 예제 메서드는 제공된 SMS_Driver 경로 및 파일 이름을 사용하여 Windows 드라이버에 대한 개체를 만듭니다. 또한 이 예제에서는 속성 true값을 IsEnabled 로 설정하여 드라이버를 사용하도록 설정합니다. 도우미 함수 GetDriverName 는 드라이버 패키지 XML에서 드라이버의 이름을 가져오는 데 사용됩니다.

참고

매개 변수는 path UNC(범용 명명 규칙) 네트워크 경로(예: \\localhost\Drivers\ATIVideo\)로 제공해야 합니다.

예제 LocaleID 에서 속성은 영어(미국)로 하드 코딩됩니다. 미국 이외 지역의 로캘이 필요한 경우 설치를 SMS_Identification 서버 WMI 클래스LocaleID 속성에서 가져올 수 있습니다.

샘플 코드 호출에 대한 자세한 내용은 코드 조각 Configuration Manager 호출을 참조하세요.

Sub ImportINFDriver(connection, path, name)  

    Dim driverClass  
    Dim inParams  
    Dim outParams  

    On Error Resume Next  

    ' Obtain an instance of the class   
    ' using a key property value.  

    Set driverClass = connection.Get("SMS_Driver")  

    ' Obtain an InParameters object specific  
    ' to the method.  
    Set inParams = driverClass.Methods_("CreateFromINF"). _  
        inParameters.SpawnInstance_()  

    ' Add the input parameters.  
    inParams.Properties_.Item("DriverPath") =  path  
    inParams.Properties_.Item("INFFile") =  name  

    ' Call the method.  
    ' The OutParameters object in outParams  
    ' is created by the provider.  
    Set outParams = connection.ExecMethod("SMS_Driver", "CreateFromINF", inParams)  

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

    outParams.Driver.IsEnabled =  True  

    Dim LocalizedSettings(0)  
    Set LocalizedSettings(0) = connection.Get("SMS_CI_LocalizedProperties").SpawnInstance_()  
    LocalizedSettings(0).Properties_.item("LocaleID") =  1033   
    LocalizedSettings(0).Properties_.item("DisplayName") = _  
            GetDriverName(outParams.Driver.SDMPackageXML, "//DisplayName", "Text")  

    LocalizedSettings(0).Properties_.item("Description") = ""          
    outParams.Driver.LocalizedInformation = LocalizedSettings  

    ' Save the driver.  
    outParams.Driver.Put_  

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 ImportInfDriver(  
    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("INFFile", name);  

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

        // Create the SMS_Driver driver instance from the management base object returned in result["Driver"].  
        IResultObject driver = connection.CreateInstance(result["Driver"].ObjectValue);  

        // Enable the driver.  
        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
.inf 파일의 이름입니다. 예를 들어 ATI.inf입니다.

코드 컴파일

이 C# 예제에는 다음이 필요합니다.

네임 스페이스

시스템

System.Collections.Generic

System.Text

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

어셈블리

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

강력한 프로그래밍

오류 처리에 대한 자세한 내용은 Configuration Manager 오류 정보를 참조하세요.

.NET Framework 보안

Configuration Manager 애플리케이션 보안에 대한 자세한 내용은 역할 기반 관리 Configuration Manager 참조하세요.

참고 항목

클래스 SMS_Driver CreateFromINF 메서드
SMS_Driver 서버 WMI 클래스
드라이버에 지원되는 플랫폼을 지정하는 방법