How to Remove a Windows Driver from a Boot Image Package
In Configuration Manager, you remove a Windows driver from an operating system deployment boot image package by removing it from the ReferencedDrivers
property of the SMS_BootImagePackage Server WMI Class object.
Note
The driver is not removed until the boot image package is refreshed and updated on the distribution points.
To remove a Windows driver from a boot image package
Set up a connection to the SMS Provider. For more information, see SMS Provider fundamentals.
Get the SMS_BootImagePackage object for the boot image package that contains the driver you want to remove.
Remove the driver from the
ReferencedDrivers
property. The driver is identified by its configuration item identifier represented by theID
property of the SMS_Driver_Details Server WMI Class object. This identifier matches theCI_ID
property ofSMS_Driver
.Commit the
SMS_BootImagePackage
object changes.Refresh the boot image package by calling
RefreshPkgSource
.
Example
The following example method removes the Windows driver from the boot image package. The package is identified by its PackageID
property and the driver is identified by its CI_ID
property.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub RemoveDriverFromBootImagePackage(connection, driverId, packageId)
Dim bootImagePackage
Dim driver
Dim driverDetails
Dim newReferencedDrivers()
Dim found
Dim index
' Get the boot image package.
Set bootImagePackage = connection.Get("SMS_BootImagePackage.PackageID='" & packageId &"'" )
found = False
index=0
' Copy the contents and leave out the driver.
For Each driver In bootImagePackage.ReferencedDrivers
If driver.ID = driverID Then
found=True
Else
Set newReferencedDrivers(index)=driver
index = index + 1
End If
Next
' Update the referenced drivers.
If found=True Then
ReDim preserve newReferencedDrivers(UBound(bootImagePackage.ReferencedDrivers)-1)
bootImagePackage.ReferencedDrivers=newReferencedDrivers
bootImagePackage.Put_
bootImagePackage.RefreshPkgSource
End If
End Sub
public void RemoveDriverFromBootImagePackage(
WqlConnectionManager connection,
int driverId,
string packageId)
{
try
{
// Get the boot image package.
IResultObject bootImagePackage = connection.GetInstance(@"SMS_BootImagePackage.packageId='" + packageId + "'");
// Get the (SMS_Driver_Details) drivers referenced by the package.
List<IResultObject> referencedDrivers = bootImagePackage.GetArrayItems("ReferencedDrivers");
foreach (IResultObject ro in referencedDrivers)
{
if (ro["ID"].IntegerValue == driverId) // Remove the driver that matches driverId.
{
referencedDrivers.Remove(ro);
break;
}
}
bootImagePackage.SetArrayItems("ReferencedDrivers", referencedDrivers);
// Commit the changes.
bootImagePackage.Put();
bootImagePackage.ExecuteMethod("RefreshPkgSource", null);
}
catch (SmsException e)
{
Console.WriteLine(e.Message);
throw;
}
}
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
Connection |
- Managed: WqlConnectionManager - VBScript: SWbemServices |
A valid connection to the SMS Provider. |
driverID |
- Managed: Integer - VBScript: Integer |
The Windows driver identifier available in SMS_Driver.CI_ID . |
PackageID |
- Managed: String - VBScript: String |
The boot image package identifier available in SMS_BootImagePackage.PackageID . |
Compiling the Code
This C# example requires:
Namespaces
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
.NET Framework Security
For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.
See Also
About Operating System Deployment Driver Management
How to Add a Windows Driver to a Configuration Manager Boot Image Package