好了没有,所以我有以下类库,这是我在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?
你是什么意思“在别处测试”?什么是返回码3?运行InstallShield时是否加载了.NET框架? – xxbbcc
WMI在权限等方面可能相当复杂 - 也许installshield在“受限制的上下文”中运行它... – Yahia
@xxbbcc“在别处测试”意味着编写另一个导入dll并使用该方法的应用程序。这样做效果很好。返回代码3(就我所能找到的)而言只是一般性错误,表示Action失败。 –