2011-10-12 163 views
1

因此,WindowsInstaller會爲安裝的軟件包提供任何ID,例如:673538CFB3FFAAC4380E12843BBFC789或BA342DECAB7C24D3699041FEA5F66C10等。如何通過已知安裝包找到此ID?Windows安裝程序ID的

+3

這個問題似乎是類似http://stackoverflow.com/questions/2467429/c-check-installed-programms – Ciprian

回答

0

下面是一個示例VBScript,它從任何給定的MSI文件中提取各種有用的屬性,而無需安裝它。您可以使用工具手動打開給定的包,如Orca

或者,如果你正在尋找識別當前已安裝的軟件包,可以使用Windows Installer API重複安裝的項目,或者在命令行中使用msiinv.exe

Option Explicit 
Dim argCount:argCount = Wscript.Arguments.Count 
Dim sPackageCode, sProductCode, sProductVersion, sDownloadURL, sConfig, sProductName 

If (argCount = 0) Then 
    WScript.Echo "Usage: msiinfo.vbs <filename>" 
    WScript.Quit 1 
End If 


Dim MSI_FILE : MSI_FILE = Wscript.Arguments(0) 

Dim filesys : Set filesys=CreateObject("Scripting.FileSystemObject") 

If Not filesys.FileExists(MSI_FILE) Then 
    WScript.Echo "Unable to find " & MSI_FILE & ", exiting" 
    WScript.Quit 1 
End If 


Dim installer, database, view, result 

Set installer = CreateObject("WindowsInstaller.Installer") 
Set database = installer.OpenDatabase (MSI_FILE, 0) 

Dim sumInfo : Set sumInfo = installer.SummaryInformation(MSI_FILE, 0) 
sPackageCode = sumInfo.Property(9) ' PID_REVNUMBER = 9, contains the package code. 

Dim sDetails : sDetails = "ProductVersion: " & getproperty("ProductVersion") & vbCrLf _ 
      & "ProductCode: " & getproperty("ProductCode") & vbCrLf _ 
      & "PackageCode: " & sPackageCode & vbCrLf _ 
      & "ProductName: " & getproperty("ProductName") 

WScript.Echo sDetails 

Function getproperty(property) 

    Set view = database.OpenView ("SELECT Value FROM Property WHERE Property='" & property & "'") 
    view.Execute 
    Set result = view.Fetch 
    getproperty = result.StringData(1) 

End Function 
0

如果你喜歡使用PowerShell:

$winInstaller = New-Object -ComObject WindowsInstaller.Installer 
$msiInstalledApps = @() 
foreach($item in $winInstaller.GetType().InvokeMember("Products","GetProperty",$null, $winInstaller, $null)){ 
    $msiInstalledApps += New-Object PSObject -Property ($hash = [ordered]@{ 
       Language = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "Language")) 
       ProductName = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "ProductName")) 
       PackageCode = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "PackageCode")) 
       Transforms = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "Transforms")) 
       AssignmentType = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "AssignmentType")) 
       PackageName = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "PackageName")) 
       InstalledProductName = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "InstalledProductName")) 
       VersionString = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "VersionString")) 
       RegCompany = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "RegCompany")) 
       RegOwner = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "RegOwner")) 
       ProductID = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "ProductID")) 
       ProductIcon = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "ProductIcon")) 
       InstallLocation = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "InstallLocation")) 
       InstallSource = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "InstallSource")) 
       InstallDate = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "InstallDate")) 
       Publisher = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "Publisher")) 
       LocalPackage = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "LocalPackage")) 
       HelpLink = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "HelpLink")) 
       HelpTelephone = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "HelpTelephone")) 
       URLInfoAbout = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "URLInfoAbout")) 
       URLUpdateInfo = $winInstaller.GetType().InvokeMember("ProductInfo","GetProperty",$null, $winInstaller, @($item, "URLUpdateInfo")) 
       }) 
} 

$msiInstalledApps