我在尝试使用 .NET ManagementObject对象调用SoftwareLicensingProduct.GetTokenActivationGrants WMI 方法时遇到问题。GetTokenActivationGrants具有以下签名:
uint32 GetTokenActivationGrants(
[out] string Grants[]
);
我正在使用以下 C# 代码:
class Program
{
private const string GRANTS_METHOD = "GetTokenActivationGrants";
static void Main(string[] args)
{
ManagementObjectSearcher productSearch = new ManagementObjectSearcher("SELECT ID, Name, ApplicationId, PartialProductKey, Description, LicenseIsAddon " +
"FROM SoftwareLicensingProduct WHERE ApplicationId = '55c92734-d682-4d71-983e-d6ec3f16059f' AND PartialProductKey <> NULL " +
"AND LicenseIsAddon = FALSE");
foreach (ManagementObject product in productSearch.Get())
{
ManagementBaseObject inParams = product.GetMethodParameters(GRANTS_METHOD);
ManagementBaseObject outParams = product.InvokeMethod(GRANTS_METHOD, inParams, null);
}
}
}
这失败并出现System.Runtime.InteropServices.COMException,我认为这是因为GetMethodParameters返回 null 而发生的。有谁知道如何正确调用像这样具有引用参数的方法?