首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >托管DLL方法在安装程序中失败

托管DLL方法在安装程序中失败
EN

Stack Overflow用户
提问于 2012-09-19 04:49:48
回答 1查看 471关注 0票数 0

好的,我有下面的类库,我用C#写的:

代码语言:javascript
复制
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()会因为安装失败而失败吗?

EN

回答 1

Stack Overflow用户

发布于 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方面做得要好得多。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12484811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档