请教达人,遍历分区搜索的代码哪错了?
本帖最后由 dhwc 于 2014-12-19 19:59 编辑写一个自动查找驱动并安装相应版本的程序,代码如下:#include <file.au3>
Dim $osVersion,$osVer,$osBit,$DrvVer,$DrvFileNmae,$DriverNumber
$osVersion = FileGetVersion( @WindowsDir & "\system32\kernel32.dll" )
$osVer = StringLeft ( $osversion, 3 )
$osBit=@OSArch
$DriverNumber = DriveGetDrive("all")
TrayTip("", "检测操作系统版本,请稍候...", 5, 1)
If $osBit="X86" Then
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="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="WanDrv6.exe"
Case $osVer="6.2"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8 x86", 5, 1)
$DrvFileNmae="WanDrv6.exe"
Case $osVer="6.3"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8.1 x86", 5, 1)
$DrvFileNmae="WanDrv6.exe"
Case $osVer="6.4"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x86 beat", 5, 1)
$DrvVer=1032
$DrvFileNmae="WanDrv6.exe"
Case $osVer="10.0"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x86", 5, 1)
$DrvVer=1032
$DrvFileNmae="WanDrv6.exe"
EndSelect
ElseIf $osBit="X64" Then
Select
Case $osVer="5.1"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows XP x64", 5, 1)
$DrvFileNmae="none"
Case $osVer="5.2"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows Server 2003 x64", 5, 1)
$DrvFileNmae="none"
Case $osVer="6.0"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows Vista x64", 5, 1)
$DrvFileNmae="none"
Case $osVer="6.1"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 7 x64", 5, 1)
$DrvFileNmae="WanDrv6.exe"
Case $osVer="6.2"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8 x64", 5, 1)
$DrvFileNmae="WanDrv6.exe"
Case $osVer="6.3"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8.1 x64", 5, 1)
$DrvFileNmae="WanDrv6.exe"
Case $osVer="6.4"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 beat x64", 5, 1)
$DrvVer=1032
$DrvFileNmae="WanDrv6.exe"
Case $osVer="10.0"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x64", 5, 1)
$DrvVer=1064
$DrvFileNmae="WanDrv6.exe"
EndSelect
ElseIf $osBit="IA64" Then
MsgBox(64,"","系统架构为" & $osBit & "!本程序不支持安腾处理器!",10)
Exit
EndIf
If $DrvFileNmae="none" 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
FindAllFile(StringUpper($DriverNumber[$i]),$DrvFileNmae)
Next
EndIf
Func FindAllFile($sDir,$FName)
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
MsgBox(64,"","找到驱动安装程序:" & $sDir & "\" & $sFile & @CRLF & "3秒之后开始安装驱动..." ,3)
Run( $sDir & "\" & $sFile )
ExitLoop
EndIf
WEnd
If $hSearch = -1 Then
MsgBox(64,"","未找到驱动安装程序!" & @CRLF & "请确认下载自由天空驱动包并解压(任意位置均可)..." ,5)
EndIf
FileClose($hSearch)
EndFunc 现在有两个问题:
1.找不到驱动的话,没有弹出提示?
2.如果存在两个以上的文件名相同的程序(比如不同版本驱动),他会全部调用,怎样只调用找到的第一个?我用ExitLoop为什么没用?
恳请解答,谢谢 达人们 帮我看看吧 感谢不尽 90行改为以下试试If $DrvFileNmae = "none" Or Not $DrvFileNmae Then 本帖最后由 afan 于 2014-12-22 14:44 编辑
#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 = "X86" Then
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 = "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 = "WanDrv6.exe"
Case $osVer = "6.2"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8 x86", 5, 1)
$DrvFileNmae = "WanDrv6.exe"
Case $osVer = "6.3"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8.1 x86", 5, 1)
$DrvFileNmae = "WanDrv6.exe"
Case $osVer = "6.4"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x86 beat", 5, 1)
$DrvVer = 1032
$DrvFileNmae = "WanDrv6.exe"
Case $osVer = "10.0"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x86", 5, 1)
$DrvVer = 1032
$DrvFileNmae = "WanDrv6.exe"
EndSelect
ElseIf $osBit = "X64" Then
Select
Case $osVer = "5.1"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows XP x64", 5, 1)
$DrvFileNmae = "none"
Case $osVer = "5.2"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows Server 2003 x64", 5, 1)
$DrvFileNmae = "none"
Case $osVer = "6.0"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows Vista x64", 5, 1)
$DrvFileNmae = "none"
Case $osVer = "6.1"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 7 x64", 5, 1)
$DrvFileNmae = "WanDrv6.exe"
Case $osVer = "6.2"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8 x64", 5, 1)
$DrvFileNmae = "WanDrv6.exe"
Case $osVer = "6.3"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 8.1 x64", 5, 1)
$DrvFileNmae = "WanDrv6.exe"
Case $osVer = "6.4"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 beat x64", 5, 1)
$DrvVer = 1032
$DrvFileNmae = "WanDrv6.exe"
Case $osVer = "10.0"
TrayTip("", "系统架构为" & $osBit & @CRLF & "系统为 Windows 10 x64", 5, 1)
$DrvVer = 1064
$DrvFileNmae = "WanDrv6.exe"
EndSelect
ElseIf $osBit = "IA64" Then
MsgBox(64, "", "系统架构为" & $osBit & "!本程序不支持安腾处理器!", 10)
Exit
EndIf
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
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 90行改为以下试试
afan 发表于 2014-12-20 10:47 http://www.autoitx.com/images/common/back.gif
提示:error: syntax error
你这个加的不对吧?我是当系统类型为2003、2008的时候提示没有当前系统类型的驱动,而不是搜索不到驱动的提示啊 第二个问题,用以下试试
afan 发表于 2014-12-20 10:55 http://www.autoitx.com/images/common/back.gif
测试通过 ,谢谢
现在就是奇怪为嘛不提示找不到驱动... 回复 6# dhwc
4#修改了下 回复dhwc
4#修改了下
afan 发表于 2014-12-20 12:21 http://www.autoitx.com/images/common/back.gif
不对,改了之后明明有驱动也提示没有,然后弹出找到驱动 回复 8# dhwc
用递归的问题。4# 回复dhwc
用递归的问题。4#
afan 发表于 2014-12-20 12:56 http://www.autoitx.com/images/common/back.gif
那就是递归的bug无法避免了吗? 那就是递归的bug无法避免了吗?
dhwc 发表于 2014-12-20 14:34 http://www.autoitx.com/images/common/back.gif
4#没用? 事实上 本来我还想加上个判断,但不知道怎么加。如果系统为win10(假设为win10x64),那么先搜索WanDrv6.exe,如果搜索不到则搜索WanDrv6.exe——因为现阶段自由天空没出win10的驱动包,用win8可替代。
如果不用递归,怎么写这个代码??恳请赐教 学习中,,好东东 4#没用?
afan 发表于 2014-12-20 14:43 http://www.autoitx.com/images/common/back.gif
测试是明明有驱动,却提示没有找到,然后搜索到的驱动程序开始运行了 测试是明明有驱动,却提示没有找到,然后搜索到的驱动程序开始运行了
dhwc 发表于 2014-12-22 14:34 http://www.autoitx.com/images/common/back.gif
4#再次修改了,我这没办法测试
页:
[1]
2