托管DLL方法在installshield中失败 [英] Managed DLL Method failing in installshield

查看:102
本文介绍了托管DLL方法在installshield中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我有以下用C#编写的类库:

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
}

没什么大不了的,GetProductId()只是搜索给定目录下的所有已安装程序.如果我在其他地方对其进行测试,它可以正常工作,但是从installshield运行(作为控制事件)时,它会失败(返回值3).

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).

我想有一个模糊的问题,但是知道为什么GetProductInfo()会因installshield而失败吗?

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

推荐答案

以下是一些适合您的阅读材料:

Here's some reading material for you:

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

原因DTF更好

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

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.

这篇关于托管DLL方法在installshield中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆