托管DLL方法在installshield中失败

时间:2021-03-05 22:40:36

Ok, so I have the following class library, which I wrote in C#:

好的,所以我有以下类库,我在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
}

Not a lot to it, GetProductId() just searches for any installed programs below a given directory. It works fine if I test it elsewhere, but when running from installshield (as a control event), it fails (return value 3).

不是很多,GetProductId()只搜索给定目录下的任何已安装的程序。如果我在其他地方测试它,它工作正常,但是当从installshield(作为控件事件)运行时,它会失败(返回值3)。

Kind of a vague question, I guess, but any idea why GetProductInfo() would be failing coming from installshield?

我想,这是一个模糊的问题,但任何想法为什么GetProductInfo()会从installshield失败?

1 个解决方案

#1


2  

Here's some reading material for you:

以下是一些阅读材料:

Deployment Tools Foundation (DTF) Managed Custom Actions

部署工具基础(DTF)托管自定义操作

Reasons DTF is Better

DTF更好的原因

BTW, the Win32_Product class is a POS. It does a very poor job of wrapping the underlying MSI API. When you switch to DTF, use the ProductInstallation::GetProducts method instead. It does a much better job of calling MsiEnumProductsEx.

顺便说一句,Win32_Product类是一个POS。它包装底层MSI API的工作非常糟糕。切换到DTF时,请改用ProductInstallation :: GetProducts方法。它在调用MsiEnumProductsEx方面做得更好。

#1


2  

Here's some reading material for you:

以下是一些阅读材料:

Deployment Tools Foundation (DTF) Managed Custom Actions

部署工具基础(DTF)托管自定义操作

Reasons DTF is Better

DTF更好的原因

BTW, the Win32_Product class is a POS. It does a very poor job of wrapping the underlying MSI API. When you switch to DTF, use the ProductInstallation::GetProducts method instead. It does a much better job of calling MsiEnumProductsEx.

顺便说一句,Win32_Product类是一个POS。它包装底层MSI API的工作非常糟糕。切换到DTF时,请改用ProductInstallation :: GetProducts方法。它在调用MsiEnumProductsEx方面做得更好。