Managed DLL Method failing in installshield

一笑奈何 提交于 2019-12-12 04:23:07

问题


Ok, so I have the following class library, which I wrote in 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).

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


回答1:


Here's some reading material for you:

Deployment Tools Foundation (DTF) Managed Custom Actions

Reasons DTF is Better

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.



来源:https://stackoverflow.com/questions/12484811/managed-dll-method-failing-in-installshield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!