使用setupAPI来卸载残留的SRS驱动失败[已解决]
本帖最后由 仙乃日 于 2010-7-12 10:26 编辑#include <SetupApi.au3>
Remove_residual_drive()
Func Remove_residual_drive()
Local $root, $x, $hDevs, $tDevInfo, $ID1, $service, $Group, $Type, $EnID
$root = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root"
RegEnumKey("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\LEGACY_PCIIDE", 1)
If @error = 0 Then
$EnID = "Root\LEGACY_PCIIDE\0000"
MsgBox(64, "", $EnID)
_SetupDiCreateDeviceDevs($EnID, $hDevs, $tDevInfo)
_SetupDiRemoveDevice($hDevs, $tDevInfo, True)
_SetupDiDestroyDeviceInfoList($hDevs)
EndIf
$x = 1
While 1
$ID1 = RegEnumKey($root, $x)
If @error <> 0 Then ExitLoop
If StringInStr($ID1, "LEGACY") Then
$service = StringTrimLeft($ID1, 7)
$Type = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & $service, "Type")
If $Type = 1 Then
$Group = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & $service, "Group")
If $Group = "SCSI Miniport" Then
$EnID = "Root\" & $ID1 & "\0000"
MsgBox(64, "", $EnID)
_SetupDiCreateDeviceDevs($EnID, $hDevs, $tDevInfo)
_SetupDiRemoveDevice($hDevs, $tDevInfo, True)
_SetupDiDestroyDeviceInfoList($hDevs)
EndIf
EndIf
EndIf
$x += 1
WEnd
EndFunc ;==>Remove_residual_drive
只能卸载一部份的残留驱动。 虽然运行后_SetupDiRemoveDevice($hDevs, $tDevInfo, True)<>0 但是运行后只是在“设备管理器”查看不到该设备罢了,没能真正卸载驱动。个人猜测,产生这个问题和驱动的INF文件不存在有关,或者是HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class下的值项缺失有关。看来只能用回老方法啦。不过还是感谢P版提供这么好的setupAPI。 还是用老办法啦!#include <LocalSecurityAuthority.au3>
system_level_privileges()
Func Remove_residual_SRSdrive()
Local $root, $x, $ImagePath, $y, $ID1, $service, $Group, $Type, $cddb, $hwid
$root = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root"
$cddb = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CriticalDeviceDatabase\"
$x = 1
While 1
$ID1 = RegEnumKey($root, $x)
If @error <> 0 Then ExitLoop
If StringInStr($ID1, "LEGACY") Then
$service = StringTrimLeft($ID1, 7)
$Type = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & $service, "Type")
If $Type = 1 Then
$Group = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & $service, "Group")
If $Group = "SCSI Miniport" Then
RegDelete($root & "\" & $ID1)
$ImagePath = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & $service, "ImagePath")
If $ImagePath <> "" Then
FileSetAttrib(@WindowsDir & "\" & $ImagePath, "-RSH")
FileDelete(@WindowsDir & "\" & $ImagePath)
EndIf
MsgBox(64, "", $service)
RegDelete("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" & $service)
$y = 1
While 1
$hwid = RegEnumKey($cddb, $y)
If @error <> 0 Then ExitLoop
If RegRead($cddb & $hwid, "Service") = $service Then
MsgBox(64, "", $cddb & $hwid)
RegDelete($cddb & $hwid)
EndIf
Remove_residual_SRSdrive()
$y += 1
WEnd
EndIf
EndIf
EndIf
$x += 1
WEnd
EndFunc ;==>Remove_residual_SRSdrive
Func system_level_privileges()
If $CmdLine = 0 Or $CmdLine <> "-System" Then
If @Compiled Then
$sApp = @ScriptFullPath
$sArg = " -System"
Else
$sApp = @AutoItExe
$sArg = " " & FileGetShortName(@ScriptFullPath) & " -System"
EndIf
_CreateProcessAsSystem($sApp, $sArg, "Winlogon.exe")
Exit
EndIf
EndFunc ;==>system_level_privileges
你这个好像没做做判断吧
获取的估计很多是非磁盘控制器部分
这样删除不会有影响吗?
看看自由天空这个贴吧http://sky123.org/thread-11561-1-1.html 研究一下怎样清理srs驱动 看过了! 就要顶!
页:
[1]