找回密码
 加入
搜索
查看: 5118|回复: 5

[系统综合] 使用setupAPI来卸载残留的SRS驱动失败[已解决]

  [复制链接]
发表于 2010-7-11 15:17:33 | 显示全部楼层 |阅读模式
本帖最后由 仙乃日 于 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
只能卸载一部份的残留驱动。

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

 楼主| 发表于 2010-7-11 15:58:03 | 显示全部楼层
虽然运行后_SetupDiRemoveDevice($hDevs, $tDevInfo, True)<>0 但是运行后只是在“设备管理器”查看不到该设备罢了,没能真正卸载驱动。个人猜测,产生这个问题和驱动的INF文件不存在有关,或者是HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class下的值项缺失有关。看来只能用回老方法啦。不过还是感谢P版提供这么好的setupAPI。
 楼主| 发表于 2010-7-12 10:26:06 | 显示全部楼层
还是用老办法啦!
#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] = 0 Or $CmdLine[1] <> "-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

评分

参与人数 1贡献 +2 收起 理由
hzxymkb + 2

查看全部评分

发表于 2010-7-27 23:18:30 | 显示全部楼层
你这个好像没做做判断吧
获取的估计很多是非磁盘控制器部分
这样删除不会有影响吗?
看看自由天空这个贴吧http://sky123.org/thread-11561-1-1.html
发表于 2011-3-14 17:19:15 | 显示全部楼层
研究一下怎样清理srs驱动
发表于 2011-6-6 05:37:15 | 显示全部楼层
看过了! 就要顶!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-2 01:33 , Processed in 0.084304 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表