2011-10-12 164 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