如何将 Windows 驱动程序添加到Configuration Manager启动映像包

在 Configuration Manager 中,通过在 SMS_BootImagePackage Server WMI 类ReferencedDrivers数组属性中添加对所需驱动程序的引用,将 Windows 驱动程序添加到作系统部署启动映像包。

注意

属性 ReferencedDrivers 是嵌入 的 SMS_Driver_Details 对象的数组,你可以向包添加多个驱动程序。 每次在分发点上更新启动映像包时,数组中的对象都会添加到启动映像包中。

驱动程序内容的位置通常从 SMS_Driver 服务器 WMI 类 对象 ContentSourcePath 属性获取,但如果原始驱动程序位置不可用,则可以重写此位置。

可能需要将网络或存储驱动程序添加到启动映像包,以便任务序列可以在 WinPE 中访问网络和磁盘资源。

仅当通过调用 Class SMS_BootImagePackage 方法中的 RefreshPkgSource 方法 刷新启动映像时,才会将驱动程序添加到映像中。

使用 Windows 程序包管理器 将驱动程序添加到映像。

将 Windows 驱动程序添加到启动映像包

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

  2. 获取要向其添加驱动程序的启动映像包的 SMS_BootImagePackage 对象。

  3. 创建并填充嵌入 SMS_Driver_Details 对象以包含驱动程序详细信息。

  4. SMS_Driver_Details 对象添加到 对象的 ReferencedDrivers 数组属性 SMS_BootImagePackage

  5. SMS_BootImagePackage提交对象更改。

示例

以下示例方法将 Windows 驱动程序添加到启动映像包。 包由其 PackageID 属性标识,驱动程序由其 CI_ID 属性标识。

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

Sub AddDriverToBootImagePackage(connection, driverId,packageId)

    Dim bootImagePackage
    Dim driver
    Dim referencedDrivers
    Dim driverDetails

    ' Get the boot image package and referenced drivers.
    Set bootImagePackage = connection.Get("SMS_BootImagePackage.PackageID='" & packageId &"'" )
    referencedDrivers = bootImagePackage.ReferencedDrivers

    ' Get the driver.
    Set driver = connection.Get("SMS_Driver.CI_ID=" & driverId )

    ' Create and populate the driver details.
    Set driverDetails = connection.Get("SMS_Driver_Details").SpawnInstance_
    driverDetails.ID=driverId
    driverDetails.SourcePath=driver.ContentSourcePath

    ' Add the driver details.
    ReDim Preserve referencedDrivers (Ubound (referencedDrivers)+1)
    Set referencedDrivers(Ubound(referencedDrivers))=driverDetails
    bootImagePackage.ReferencedDrivers=referencedDrivers

    bootImagePackage.Put_
    bootImagePackage.RefreshPkgSource

End Sub
public void AddDriverToBootImagePackage(
    WqlConnectionManager connection,
    int driverId,
    string packageId)
{
    try
    {
        // Get the boot image package.
        IResultObject bootImagePackage = connection.GetInstance(@"SMS_BootImagePackage.packageId='" + packageId + "'");

        // Get the driver.
        IResultObject driver = connection.GetInstance("SMS_Driver.CI_ID=" + driverId);

        // Get the drivers that are referenced by the package.
        List<IResultObject> referencedDrivers = bootImagePackage.GetArrayItems("ReferencedDrivers");

        // Create and populate an embedded SMS_Driver_Details. This is added to the ReferencedDrivers array.
        IResultObject driverDetails = connection.CreateEmbeddedObjectInstance("SMS_Driver_Details");

        driverDetails["ID"].IntegerValue = driverId;
        driverDetails["SourcePath"].StringValue = driver["ContentSourcePath"].StringValue;

        // Add the driver details to the array.
        referencedDrivers.Add(driverDetails);

        // Add the array to the boot image package.
        bootImagePackage.SetArrayItems("ReferencedDrivers", referencedDrivers);

        // Commit the changes.
        bootImagePackage.Put();
        bootImagePackage.ExecuteMethod("RefreshPkgSource", null);
    }
    catch (SmsException e)
    {
        Console.WriteLine(e.Message);
        throw;
    }
}

示例方法具有以下参数:

参数 类型 说明
Connection -管理:WqlConnectionManager
- VBScript: SWbemServices
与 SMS 提供程序的有效连接。
driverID -管理: String
- VBScript: String
SMS_Driver.CI_ID可用的 Windows 驱动程序标识符。
PackageID -管理: String
- VBScript: String
SMS_BootImagePackage.PackageID可用的启动映像包标识符。

编译代码

此 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基于角色的管理

另请参阅

关于作系统部署驱动程序管理如何从启动映像包中删除 Windows 驱动程序