好了沒有,所以我有以下類庫,這是我在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失敗。 –