好的,所以我有以下用 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)。
我猜这是一个模糊的问题,但知道为什么GetProductInfo()
installshield 会失败吗?