Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

.net - Getting List Of Installed Products c#

To Install/Uninstall/Update our software, our custom installer uses WindowsInstaller.Installer.Products to get the list of installed products from windows registry.

And on some client machines, an unknown software is probably adding a new entry to the registry 'HKEY_LOCAL_MACHINESOFTWAREClassesInstallerProducts' a key with name something like 'ABCD'. This is causing WindowsInstaller.Installer.Products to throw an exception. I can re create this scenario by manually adding a registry key entry into 'HKEY_LOCAL_MACHINESOFTWAREClassesInstallerProducts' named 'test'. And if I rename test to a new GUID then the simulated problem gets solved.

Can you suggest any possible workaround/solution?

Using MSIINV.exe tool would be difficult, as that is a 3rd party tool, but that seems to help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'd take a look at the Microsoft.Deployment.WindowsInstaller namespace found in Windows Installer XML (WiX) Deployment Tools Foundation (DTF). It has:

public static IEnumerable<ProductInstallation> GetProducts(
    string productCode,
    string userSid,
    UserContexts context
)

productCode (String)

ProductCode (GUID) of the product instances to be enumerated. Only instances of products within the scope of the context specified by the userSid and context parameters will be enumerated. This parameter may be set to null to enumerate all products in the specified context.

userSid (String)

Specifies a security identifier (SID) that restricts the context of enumeration. A SID value other than s-1-1-0 is considered a user SID and restricts enumeration to the current user or any user in the system. The special SID string s-1-1-0 (Everyone) specifies enumeration across all users in the system. This parameter can be set to null to restrict the enumeration scope to the current user. When context is set to the machine context only, userSid must be null.

context (UserContexts)

Specifies the user context.

that wraps the Win32 MSI API MsiEnumProductsEx function. This brings back a collection of ProductInstallation that you can do Linq queries against to find out anything you need to know about installed MSI's.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...