好的,我有下面的类库,我用C#写的:
public class Program
{
public void GetProductID(string location, out string productId)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
ManagementObjectCollection collection = searcher.Get();
var item = new Win32Product();
//var crap = (collection as IEnumerable<ManagementObject>).Where(o => o["InstallLocation"].ToString().StartsWith(location));
foreach (ManagementObject obj in collection)
{
try
{
item = new Win32Product();
item.IdentifyingNumber = (string)obj["IdentifyingNumber"];
item.InstallLocation = (string)obj["InstallLocation"];
item.Name = (string)obj["Name"];
}
catch
{ } //shut up. I know it's an empty catch block. Its fine.
//If there are exceptions thrown, I don't want the data, I just
//want to keep running.
}
productId = item.ProductID.ToString();
}
}
public class Win32Product
{
//properties
}这并不重要,GetProductId()只是搜索给定目录下的任何已安装的程序。如果我在其他地方测试它,它可以工作得很好,但是当从installshield (作为控制事件)运行时,它失败了(返回值3)。
我想,这是一个模糊的问题,但是你知道为什么GetProductInfo()会因为安装失败而失败吗?
发布于 2012-09-19 05:19:33
这里有一些给你的阅读材料:
Deployment Tools Foundation (DTF) Managed Custom Actions
Reasons DTF is Better
顺便说一句,Win32_Product类是一个POS机。它在包装底层MSI API方面做得非常糟糕。切换到DTF时,请改用ProductInstallation::GetProducts方法。它在调用MsiEnumProductsEx方面做得要好得多。
https://stackoverflow.com/questions/12484811
复制相似问题