WMI methods using ManagementObject.InvokeMethod()

泪湿孤枕 提交于 2019-12-13 03:59:19

问题


I am having issues when tyring to invoke the SoftwareLicensingProduct.GetTokenActivationGrants WMI method using a .NET ManagementObject object. GetTokenActivationGrants has the following signature:

uint32 GetTokenActivationGrants(
  [out]  string Grants[]
);

I'm using the following C# code:

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);
        }

    }
}

This fails with a System.Runtime.InteropServices.COMException which I believe is occurring because the GetMethodParameters returns null. Does anyone know how to properly invoke a method like this that has a referenced argument?


回答1:


As @Hans commented, this is an expected error. The problem is that none of the expected or possible errors are documented anywhere in the MSDN library. With a little digging you can find them in %SystemRoot%\System32\slmgr\0409\slmgr.ini or http://gallery.technet.microsoft.com/office/68b80aba-130d-4ad4-aa45-832b1ee49602.



来源:https://stackoverflow.com/questions/19033703/wmi-methods-using-managementobject-invokemethod

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!