本帖最后由 wgboy 于 2010-12-7 10:54 编辑
以下代码可以取出注册表中正规软件安装信息
如何能查出电脑中的绿色软件啊。有没有好的正则表达之类。。$i = 0
While 1
$i = $i + 1
$var = RegEnumKey("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
If @error <> 0 Then ExitLoop
WEnd
$iTotal = $i
For $i = 1 To $iTotal Step 1 ;对注册表进行扫描
$var = RegEnumKey("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $i)
If @error <> 0 Then ExitLoop
$iRegExp = StringRegExp($var, 'KB\d\d\d\d', 0) ; 剔除操作系统更新包
If $iRegExp = 1 Then
ContinueLoop
EndIf
$SoftwareName = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $var, "DisplayName") ; 剔除空的注册表键值
If @error = -1 Then
ContinueLoop
EndIf
If StringInStr($SoftwareName, "Microsoft Office", 0, 1) <> 0 And Not StringInStr($SoftwareName, "Visio", 0, 1) <> 0 And Not StringInStr($SoftwareName, "project", 0, 1) <> 0 Then
ContinueLoop
EndIf
; 提取安装软件的名称,版本和安装路径
$SoftwareVersion = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $var, "DisplayVersion")
$len = StringLen($SoftwareVersion)
; 有些软件在注册表中的版本信息字段定义为Inno Setup: Setup Version
If $len = 0 Then
$SoftwareVersion = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $var, "Inno Setup: Setup Version")
EndIf
; 提取软件的名称、版本号和安装路径
$SoftwareInstallLocation = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $var, "InstallLocation")
$len = StringLen($SoftwareInstallLocation)
If $len = 0 Then
$DisplayStr = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $var, "Readme")
$len = StringLen($DisplayStr)
If $len = 0 Then
$DisplayStr = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $var, "DisplayIcon")
$len = StringLen($DisplayStr)
If $len = 0 Then
$DisplayStr = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $var, "UninstallString")
EndIf
EndIf
$len = StringLen($DisplayStr)
If $len = 0 Then
ContinueLoop
EndIf
$array = StringSplit($DisplayStr, '\', 1)
$num = $array[0] - 1
For $j = 1 To $num
$SoftwareInstallLocation = $SoftwareInstallLocation & $array[$j] & ""
Next
EndIf ;<=== 提取软件的名称、版本号和安装路径 结束
$SoftwareInstallLocation = StringRegExpReplace($SoftwareInstallLocation, '"', "")
; 去掉驱动程序和一些windows自带的软件包
If StringInStr($SoftwareInstallLocation, "file:") <> 0 _
Or StringInStr($SoftwareInstallLocation, "MsiExec.exe") <> 0 _
Or StringInStr($SoftwareInstallLocation, "RunDll32") <> 0 _
Or StringInStr($SoftwareInstallLocation, "%ProgramFiles%") <> 0 _
Or StringInStr($SoftwareInstallLocation, "c:\windows") <> 0 _
Or StringInStr($SoftwareInstallLocation, "\Common Files") <> 0 _
Or StringInStr($SoftwareInstallLocation, "") = 0 Then
ContinueLoop
EndIf
|