如何检测安装过的软件
大家好,请问用AUTOIT script如何检测Windows已经安装的补丁或者软件?比如看系统有没有安装.net framework 2.0或以上,如果没有就启动安装,有就跳过谢谢 检查.net framework是否安装及安装了的版本。
#Include <Array.au3>
#Include <WinAPIEx.au3>
Global $hKey, $Count, $Num = 1
$hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\.NETFramework')
If @error Then
MsgBox(0,0,"未安装.NETFramework")
Exit
Else
$Count = _WinAPI_RegQueryInfoKey($hKey)
Dim $reg_array
For $i = 0 To $Count
If StringRegExp( _WinAPI_RegEnumKey($hKey, $i),'v\d\.\d.*',0) Then
$Num+=1
ReDim $reg_array[$Num]
$reg_array[$Num-1]=_WinAPI_RegEnumKey($hKey, $i)
$reg_array=UBound($reg_array)-1
EndIf
Next
_WinAPI_RegCloseKey($hKey)
_ArrayDisplay($reg_array)
EndIf
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
查这个下面的键,windows的程序管理器就是读这里的信息,net framework和其他运行库、组件、补丁都可以在这里找到的。 不知道直接走注册表可行不! #include <Array.au3>
#include <WinAPIEx.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $iI, $iTimer, $hListView
; 创建界面
GUICreate("ListView Add Array", 500, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 460, 268)
_GUICtrlListView_SetUnicodeFormat($hListView, False)
GUISetState()
; 添加列
_GUICtrlListView_AddColumn($hListView, "键名", 100)
_GUICtrlListView_AddColumn($hListView, "软件名", 100)
_GUICtrlListView_AddColumn($hListView, "安装路径", 100)
_GUICtrlListView_AddColumn($hListView, "卸载文件名", 100)
Global $hKey, $Count, $Num = 1
$hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall')
If @error Then
MsgBox(0, 0, "未安装.NETFramework")
Exit
Else
$Count = _WinAPI_RegQueryInfoKey($hKey)
_GUICtrlListView_SetItemCount($hListView, $Count)
Dim $reg_array[$Count]
For $i = 0 To UBound($reg_array) - 1
$reg_array[$i] = _WinAPI_RegEnumKey($hKey, $i)
$reg_array[$i] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $reg_array[$i], "DisplayName")
$reg_array[$i] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $reg_array[$i], "InstallDir")
$reg_array[$i] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $reg_array[$i], "UninstallString")
Next
_WinAPI_RegCloseKey($hKey)
;_ArrayDisplay($reg_array)
EndIf
_GUICtrlListView_AddArray($hListView, $reg_array)
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
感谢楼主分享 谢谢楼主,太感谢了 回复 5# 3mile
没有测试成功:
ERROR: $PROCESS_VM_READ previously declared as a 'Const'
Global Const $PROCESS_VM_READ = 0x00000010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~^
D:\autoit3\Include\ProcessConstants.au3(22,53) : ERROR: $PROCESS_QUERY_INFORMATION previously declared as a 'Const'
Global Const $PROCESS_QUERY_INFORMATION = 0x00000400
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:\zgk_2010\autoit\excises\temp.au3 - 2 error(s), 0 warning(s)
,那个$PROCESS_VM_READ 在哪呢? 没有测试成功:
ERROR: $PROCESS_VM_READ previously declared as a 'Const'
Global Const $PROCESS_VM_READ = 0x00000010
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~^
D:\autoit3\Include\ProcessConstants.au3(22,53) : ERROR: $PROCESS_QUERY_INFORMATION previously declared as a 'Const'
Global Const $PROCESS_QUERY_INFORMATION = 0x00000400
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:\zgk_2010\autoit\excises\temp.au3 - 2 error(s), 0 warning(s)
,那个$PROCESS_VM_READ 在哪呢?
newuser 发表于 2010-9-13 10:30 http://www.autoitx.com/images/common/back.gif
应该是这里吧?D:\autoit3\Include\ProcessConstants.au3(22,53) 俺是菜鸟学习了收藏 回复 9# 3mile
是那里,但错在哪呢?它不是库函数吗?如果没有,应该想缺#include <WinAPIEx.au3>的错误提示啊! HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
删除该项就是卸载吗 回复 11# newuser
我只是猜想,应该是包含文件中的定义常量有冲突吧。 回复 13# 3mile
它不是库文件吗?我已经#include他了!
该如何修正它呢?修改库文件,老实说,想都没想过! 回复 5# 3mile
代码 16 行应用参数 True ,否则中文烂码。。。。。。。
不知为何检测不到安装路径。。。。