如何在 Configuration Manager 中启用或禁用 Windows 驱动程序

在 Configuration Manager 中,通过设置 IsEnabledSMS_Driver Server WMI 类对象的 属性,在操作系统部署驱动程序目录中启用或禁用 Windows 驱动程序。 可以禁用驱动程序,以防止在任务序列中的“自动应用驱动程序”操作安装驱动程序。

启用或禁用 Windows 驱动程序

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

  2. SMS_Driver获取要启用或禁用的驱动程序的对象。

  3. IsEnabled 属性设置为 true 以启用驱动程序,或 设置为 false 以禁用驱动程序。

  4. SMS_Driver提交对象更改。

示例

以下示例方法根据 参数的值 enableDriver 启用或禁用驱动程序。

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

Sub EnableDriver(connection,driverID,vEnableDriver)  

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

        ' Set the flag.  
        driver.IsEnabled=vEnableDriver  

        ' Commit changes.  
        driver.Put_  

End Sub  
public void EnableDriver(  
    WqlConnectionManager connection,   
    int driverID,   
    bool enableDriver)  
{  
    try  
    {  
        // Get the driver.  
        IResultObject driver = connection.GetInstance("SMS_Driver.CI_ID=" + driverID);  

        // Set the flag.  
        driver["IsEnabled"].BooleanValue = enableDriver;  

        // Commit the changes.  
        driver.Put();  
    }  
    catch (SmsException e)  
    {  
        Console.WriteLine("Failed: " + e.Message);  
        throw;  
    }  
}  

示例方法具有以下参数:

参数 类型 说明
connection -管理: WqlConnectionManager
- VBScript: SWbemServices
与 SMS 提供程序的有效连接。
driverID -管理: Integer
- VBScript: Integer
SMS_Driver.CI_ID可用的 Windows 驱动程序标识符。
enableDriver -管理: String
- VBScript: String
用于启用或禁用驱动程序的标志。

true - 驱动程序已启用。

false - 驱动程序已禁用。

编译代码

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