2015-07-13 101 views
0

我需要找到安裝在我的機器上的軟件的版本。這樣做的代碼是安裝該軟件的版本

Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE 
strComputer = "." 
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 
strkey1= "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" 
strEntry1a = "DisplayName" 
strEntry1b = "QuietDisplayName" 
strEntry3 = "VersionMajor" 
strEntry4 = "VersionMinor" 

'to get result in tabular format in html 
strResult = "<body><table border=1 cellpadding=5 style=margin-left:50px;><tr><th>Sl No.</th><th>Softwares</th><th>Version</th></tr>" 
Dim cnt 
cnt=0 

'getting the list from win32:_64 bit installed softwares 
Set objReg = GetObject("winmgmts://" & strComputer & _ 
"/root/default:StdRegProv") 
objReg.EnumKey HKLM, strKey, arrSubkeys 

For Each strSubkey In arrSubkeys 
    intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _ 
    strEntry1a, strValue1) 
    If intRet1 <> 0 Then 
     objReg.GetStringValue HKLM, strKey & strSubkey, _ 
     strEntry1b, strValue1 
    End If 
    objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry3, intValue3 
    objReg.GetDWORDValue HKLM, strKey & strSubkey, strEntry4, intValue4 
    If strValue1 <> "" Then 
     'to check the duplicates 
     If InStr(strResult,strValue1 & VbCrLf & "</td>")=0 Then 
      cnt=cnt+1 
      strResult = strResult & "<tr><td>"&cnt & "</td><td>" & strValue1 & VbCrLf & "</td><td>" &intValue3 & "." &intValue4 & "</td></tr>" 
     End If 
    End If 
Next 

但問題是它沒有給出完整版本的軟件。 例如:對於vlc 2.7.1,其不打印任何內容,對於其他打印任何其一半,即8.1而不是8.1.61001。如何打印完整版本。

回答

1

閱讀DisplayVersion字符串而不是DWORD值VersionMajorVersionMinor

objReg.GetStringValue HKLM, strKey & strSubkey, "DisplayVersion", version 
+0

它的工作。謝謝:)但有一個問題,它沒有打印像MATLAB,vlc,7-zip等少數軟件的版本。可能是什麼原因。 – user387600

+0

@ user387600您發佈的代碼不檢查每個用戶的安裝,並且在64位系統上不檢查32位註冊表分支('strKey1')。 –

相關問題