2012-09-18 46 views
0

好了没有,所以我有以下类库,这是我在C#中写道:托管DLL方法的InstallShield

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?

+0

你是什么意思“在别处测试”?什么是返回码3?运行InstallShield时是否加载了.NET框架? – xxbbcc

+0

WMI在权限等方面可能相当复杂 - 也许installshield在“受限制的上下文”中运行它... – Yahia

+0

@xxbbcc“在别处测试”意味着编写另一个导入dll并使用该方法的应用程序。这样做效果很好。返回代码3(就我所能找到的)而言只是一般性错误,表示Action失败。 –

回答

2

下面是一些阅读材料,为您提供:

Deployment Tools Foundation (DTF) Managed Custom Actions

Reasons DTF is Better

BTW,Win32_Product类是POS。它在包装底层的MSI API方面做得很差。当您切换到DTF时,请使用ProductInstallation :: GetProducts方法。它在调用MsiEnumProductsEx方面做得更好。

+0

我想今天看看这个,但我得到一个404的链接到下载,从你的博客(顺便说一句,我印象深刻)。我也无法通过WiX的sourceforge找到它。任何地方我可以找到这个下载? –

+0

http://wix.codeplex.com/releases/view/93929 –