如何从 Windows 驱动程序中删除类别
在 Configuration Manager 中,可以通过从 SMS_Driver 服务器 WMI 类CategoryInstance_UniqueIDs
数组属性中删除类别的唯一标识符,从 Windows 驱动程序中删除类别。
从 Windows 驱动程序中删除类别
设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识。
获取要从中删除类别的驱动程序的 SMS_Driver 对象。
从与所需类别匹配的 SMS_CategoryInstance 服务器 WMI 类 对象获取类别名称标识符。
从 SMS_Driver 服务器 WMI 类 对象
CategoryInstance_UniqueIDs
数组属性中删除类别标识符。提交 SMS_Driver服务器 WMI 类 更改。
示例
以下示例方法从 Windows 驱动程序中删除类别。
driverID
是有效的 SMS_Driver服务器 WMI 类 对象。 有关详细信息,请参阅 关于操作系统部署驱动程序管理。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
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;
}
}
示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
Connection |
-管理:WqlConnectionManager - VBScript: SWbemServices |
与 SMS 提供程序的有效连接。 |
driver |
-管理: IResultObject - VBScript: SWbemObject |
Windows 驱动程序。 它是 SMS_Driver服务器 WMI 类的实例。 |
categoryName |
-管理: String - VBScript: String |
现有类别的名称。 这与 SMS_CategoryInstance 服务器 WMI 类e LocalizedCategoryInstanceName 属性匹配。 |
编译代码
此 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基于角色的管理。