这是我自己用的一个自动安装INF驱动的脚本,和系统的“添加新硬件向导”一样,只是做成了自动点击
前提是需要有 dpinst.exe, 32位和64位系统用的不一样,上网搜索可分别下载
只需要指定INF文件所在目录即可,不需要提供硬件ID#RequireAdmin
#NoTrayIcon
Local $hWnd
;Local $InstallDir = "F:\Driver\Video\XGI\Windows\xgi_volariz7_11404\2008R2"
;Local $InstallDir = "e:\Driver\Storage\RocketRAID 264x\Windows\Win7_08_08R2_x64"
Local $InstallDir = StringReplace($CmdLineRaw, '"', '')
FileChangeDir(@ScriptDir)
If Not FileExists($InstallDir) Or Not FileExists(@ScriptDir & "\dpinst64.exe") Or Not FileExists(@ScriptDir & "\dpinst32.exe") Then
Exit
EndIf
If @OSArch = "X64" Then
$CommandName = 'dpinst64.exe /LM /F /PATH "' & $InstallDir & '"'
Else
$CommandName = 'dpinst32.exe /LM /F /PATH "' & $InstallDir & '"'
EndIf
$InstallPID = Run($CommandName) ;启动安装程序
If @error Then
Exit
Else
$TimeOut = 100
$Switch = False
While 1
$WinList = WinList("[CLASS:#32770]")
For $p = 1 To $WinList[0][0]
;ToolTip(WinGetProcess($WinList[$p][1]) &"--"& $InstallPID)
If WinGetProcess($WinList[$p][1]) = $InstallPID Then
$hWnd = $WinList[$p][1]
$Switch = True
ExitLoop
EndIf
Next
If $Switch = True Or $TimeOut <= 0 Then ExitLoop ;时间超过10秒还不出现窗口则退出
Sleep(100)
$TimeOut -= 1
WEnd
$Handle = WinGetTitle($hWnd) ;取窗口标题
$Title = "[TITLE:" & $Handle & ";CLASS:#32770]" ;完整窗口标题,用于区分其它窗口
If $Handle <> "" Then
;WinSetTrans($Title, "", 0)
ControlClick($Title, "", "Button2")
While 1
If ControlCommand($Title, "", "Button7", "IsVisible", "") Then
ProcessClose($InstallPID)
Exit
EndIf
If Not ProcessExists($InstallPID) Then Exit
Sleep(500)
WEnd
Else
Exit
EndIf
EndIf
|