How to Remove a Category from a Windows Driver
Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2
In Microsoft System Center Configuration Manager 2007, you remove a category from a Windows driver by removing the unique identifier for the category from the SMS_Driver Server WMI ClassCategoryInstance_UniqueIDs array property.
To remove a category from a Windows driver
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Get the SMS_Driver object for the driver that you want remove the category from.
Get the category name identifier from the SMS_CategoryInstance Server WMI Class object that matches the desired category.
Remove the category identifier from the SMS_Driver Server WMI Class object CategoryInstance_UniqueIDs array property.
Commit the SMS_Driver Server WMI Class changes.
Example
The following example method removes a category from a Windows driver. driverID is a valid SMS_Driver Server WMI Class object. For more information, see About Operating System Deployment Driver Management.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub RemoveDriverCategory(connection,driver,categoryName)
Dim results
Dim driverCategoryID
Dim category
Dim categories
Dim i
If IsNull(driver.CategoryInstance_UniqueIDs) _
or UBound (driver.CategoryInstance_UniqueIDs) = -1 Then
' There are no categories, so quit.
Wscript.Echo "No categories found"
Exit Sub
End If
Set results = _
connection.ExecQuery("SELECT * From SMS_CategoryInstance WHERE LocalizedCategoryInstanceName = '" _
+ categoryName+ "'")
' If the category was found, delete, if it is there, from the driver.
For Each category In results
' Destination for copied categories.
categories = Array(driver.CategoryInstance_UniqueIDs)
i=0
For Each driverCategoryID in driver.CategoryInstance_UniqueIDs
If driverCategoryID = category.CategoryInstance_UniqueID Then
' Found it, so skip it.
Redim Preserve categories (UBound(categories))
Else
' Copy the category.
categories(i) = driverCategoryID
i=i+1
End If
Next
' Make sure the array is empty.
if i = 0 Then
Redim categories(-1)
End If
driver.CategoryInstance_UniqueIDs = categories
driver.Put_
Next
End Sub
public void RemoveDriverCategory(WqlConnectionManager connection,
IResultObject driver,
string categoryName)
{
try
{
// Get the category.
IResultObject results =
connection.QueryProcessor.ExecuteQuery(
"SELECT * From SMS_CategoryInstance WHERE LocalizedCategoryInstanceName = '"
+ categoryName
+ "'");
ArrayList driverCategories = new ArrayList(driver["CategoryInstance_UniqueIDs"].StringArrayValue);
// Remove the category from the driver.
foreach (IResultObject category in results)
{
driverCategories.Remove(category["CategoryInstance_UniqueID"].StringValue);
}
// Update the driver.
driver["CategoryInstance_UniqueIDs"].StringArrayValue = (string[])driverCategories.ToArray(typeof(string));
driver.Put();
}
catch(SmsException e)
{
Console.WriteLine("Failed to remove category :" + e.Message);
throw;
}
}
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
Connection |
|
A valid connection to the SMS Provider. |
driver |
|
The Windows driver. It is an instance of SMS_Driver Server WMI Class. |
categoryName |
|
The name of an existing category. This matches the SMS_CategoryInstance Server WMI Classe LocalizedCategoryInstanceName property. |
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.
Security
For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.
See Also
Concepts
About Operating System Deployment Driver Management
Operating System Deployment Driver Management
How to Add a Category to a Windows Driver