In System Center 2012 Configuration Manager, 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

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Get the SMS_Driver object for the driver that you want remove the category from.

  3. Get the category name identifier from the SMS_CategoryInstance Server WMI Class object that matches the desired category.

  4. Remove the category identifier from the SMS_Driver Server WMI Class object CategoryInstance_UniqueIDs array property.

  5. 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.

Visual Basic Script  Copy Code
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   
C#  Copy Code
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

  • Managed:WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

driver

  • Managed: IResultObject

  • VBScript: SWbemObject

The Windows driver. It is an instance of SMS_Driver Server WMI Class.

categoryName

  • Managed: String

  • VBScript: String

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 Securing Configuration Manager Applications.

See Also