托管DLL方法在installshield中失败

时间:2012-09-18 20:49:48

标签: c# installer windows-installer installshield managed

好的,所以我有以下类库,我用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()将来自installshield失败?

1 个答案:

答案 0 :(得分:2)

以下是一些阅读材料:

Deployment Tools Foundation (DTF) Managed Custom Actions

Reasons DTF is Better

BTW,Win32_Product类是一个POS。它包装底层MSI API的工作非常糟糕。切换到DTF时,请改用ProductInstallation :: GetProducts方法。它可以更好地调用MsiEnumProductsEx。