找回密码
 加入
搜索
楼主: dhwc

[AU3基础] 请教达人,遍历分区搜索的代码哪错了?

  [复制链接]
 楼主| 发表于 2014-12-22 19:51:31 | 显示全部楼层
本帖最后由 dhwc 于 2014-12-22 19:54 编辑
4#再次修改了,我这没办法测试
afan 发表于 2014-12-22 14:46


谢谢你!高人,测试通过,可以讲解下你加的那个语句吗?

我尝试加入更多功能——优先搜索当前目录、全盘搜索有多个不同版本驱动优先使用文件日期较后的版本、如果是win10先搜索[Win10.x64]WanDrv6.exe搜不到就用win8驱动代替,如果不会,还请继续指教,谢谢
 楼主| 发表于 2014-12-22 20:07:22 | 显示全部楼层
代码精简了下:
#include <file.au3>
Dim $osVersion, $osVer, $osBit, $DrvVer, $DrvFileNmae, $DriverNumber
$osVersion = FileGetVersion(@WindowsDir & "\system32\kernel32.dll")
$osVer = StringLeft($osVersion, 3)
MsgBox(0, 0, '"' & $osVer & '"')
$osBit = @OSArch
$DriverNumber = DriveGetDrive("all")

TrayTip("", "检测操作系统版本,请稍候...", 5, 1)
If $osBit = "IA64" Then
        MsgBox(64, "", "系统架构为" & $osBit & "!本程序不支持安腾处理器!", 10)
        Exit
EndIf  
        
Select
                Case $osVer = "5.0"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 2000", 5, 1)
                        $DrvFileNmae = "none"

                Case $osVer = "5.1"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows XP x86", 5, 1)
                        $DrvFileNmae = "[WinXP.x86]WanDrv6.exe"

                Case $osVer = "5.2"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows Server 2003 x86", 5, 1)
                        $DrvFileNmae = "none"

                Case $osVer = "6.0"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows Vista x86", 5, 1)
                        $DrvFileNmae = "none"

                Case $osVer = "6.1"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 7 x86", 5, 1)
                        $DrvFileNmae = "[Win7." & $osBit & "]WanDrv6.exe"

                Case $osVer = "6.2"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8 x86", 5, 1)
                        $DrvFileNmae = "[Win8." & $osBit & "]WanDrv6.exe"

                Case $osVer = "6.3"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8.1 x86", 5, 1)
                        $DrvFileNmae = "[Win8." & $osBit & "]WanDrv6.exe"

                Case $osVer = "6.4"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x86 beat", 5, 1)
                        $DrvVer = 1032
                        $DrvFileNmae = "[Win10." & $osBit & "]WanDrv6.exe"

                Case $osVer = "10.0"
                        TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x86", 5, 1)
                        $DrvVer = 1032
                        $DrvFileNmae = "[Win10." & $osBit & "]WanDrv6.exe"
        EndSelect

If $DrvFileNmae = "none" Or Not $DrvFileNmae Then
        MsgBox(64, "", "没有当前系统的驱动安装程序~!" & @CRLF & "请确认你的系统为WinXP、Win7、Win8、Win10!", 10)
        Exit
EndIf

If FileExists(@HomeDrive & "" & "Drivers") Then
        MsgBox(64, "", "已存在" & @HomeDrive & "盘下Drivers目录,3秒后删除...", 3)
        FileSetAttrib(@HomeDrive & "" & "Drivers", "-RASH")
        DirRemove(@HomeDrive & "" & "Drivers", 1)
EndIf

If Not @error Then
        For $i = 1 To $DriverNumber[0]
                FindAllFile(StringUpper($DriverNumber[$i]), $DrvFileNmae)
                If IsDeclared("~" & StringToBinary($DrvFileNmae)) Then ExitLoop
        Next
        If Not IsDeclared("~" & StringToBinary($DrvFileNmae)) Then
                MsgBox(64, "", "未找到驱动安装程序!" & @CRLF & "请确认下载自由天空驱动包并解压(任意位置均可)...", 5)
        EndIf
EndIf

Func FindAllFile($sDir, $FName)
        If IsDeclared("~" & StringToBinary($FName)) Then Return
        Local $hSearch = FileFindFirstFile($sDir & "\*.*")
        If $hSearch = -1 Then Return
        While 1
                Local $sFile = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then
                        FindAllFile($sDir & "" & $sFile, $FName)
                        ContinueLoop
                EndIf
                If $sFile = $FName Then
                        Assign("~" & StringToBinary($FName), 1, 2)
                        MsgBox(64, "", "找到驱动安装程序:" & $sDir & "" & $sFile & @CRLF & "3秒之后开始安装驱动...", 3)
                        Run($sDir & "" & $sFile)
                        ExitLoop
                EndIf
        WEnd
        FileClose($hSearch)
EndFunc   ;==>FindAllFile
发表于 2014-12-25 14:00:32 | 显示全部楼层
学习了
发表于 2014-12-25 21:22:05 | 显示全部楼层
来学习学习
发表于 2014-12-25 21:27:00 | 显示全部楼层
观一下,学习一下,楼主好人
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-16 06:37 , Processed in 0.069739 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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