本文仅仅作为禁用设备,启用命令已经注释
win10里,配置文件需要填入设备的“设备实例路径”,下方给出了配置文件示例

#include <SetupAPI.au3>
#include <Array.au3>
;禁用设备
Global $hDevs, $tDevInfo, $sDeviceID, $sDelayTime
If FileExists(@ScriptDir & "\deviceid.ini") = 0 Then
    _CreateINI()
EndIf
$sDelayTime = IniRead(@ScriptDir & "\deviceid.ini", "DELAY", "TIME", "")
$aDeviceID = IniReadSection(@ScriptDir & "\deviceid.ini", "DEVICE")
If @error Then
    Exit
EndIf
Sleep($sDelayTime * 1000)
;~ _ArrayDisplay($aDeviceID)
For $i=0 To $aDeviceID[0][0]
    $bCheckDevice = _SetupDiCreateDeviceDevs($aDeviceID[$i][1], $hDevs, $tDevInfo)
        If  $bCheckDevice = 0 Then
            $i = $i + 1
;~         ConsoleWrite($bCheckDevice)
            _SetupDiCreateDeviceDevs($aDeviceID[$i][1], $hDevs, $tDevInfo)
            $fResult = _SetupDiDisableDevice($hDevs, $tDevInfo, True) ; 禁用
        Else
            _SetupDiCreateDeviceDevs($aDeviceID[$i][1], $hDevs, $tDevInfo)
            $fResult = _SetupDiDisableDevice($hDevs, $tDevInfo, True) ; 禁用
        EndIf
Next
_SetupDiDestroyDeviceInfoList($hDevs)
Exit

Func _CreateINI()
    IniWrite(@ScriptDir & "\deviceid.ini", "DELAY", "TIME", "0")
    IniWrite(@ScriptDir & "\deviceid.ini", "DEVICE", "1", "")
    IniWrite(@ScriptDir & "\deviceid.ini", "DEVICE", "2", "")
    FileWriteLine(@ScriptDir & "\deviceid.ini", ";TIME=后为延迟时间(秒)执行,防止驱动未PNP完成" & @CRLF & ";请在上方=后填入设备实例路径,请自行在设备管理器查看")
EndFunc
最后修改:2023 年 03 月 11 日
如果觉得我的文章对你有用,请随意赞赏