0

为什么会这样:

using System;
using System.Management;

public class InvokeMethod
{
    public static void Main()
    {
        ManagementClass processClass = new ManagementClass("Win32_Process");
        ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
        inParams["CommandLine"] = "calc.exe";
        InvokeMethodOptions methodOptions = new InvokeMethodOptions(null, System.TimeSpan.MaxValue);
        ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, methodOptions);
    }
}

这不起作用:

using System;
using System.Management;
public class Program
{
    public static void Main()
    {
        ManagementClass rename = new ManagementClass("Win32_ComputerSystem");
        ManagementBaseObject inParams = rename.GetMethodParameters("Rename");
        inParams.SetPropertyValue("Name", "Name1234");
        InvokeMethodOptions methodOptions = new InvokeMethodOptions(null, System.TimeSpan.MaxValue);
        ManagementBaseObject outParams = rename.InvokeMethod("Rename", inParams, methodOptions);
        Console.Read();
    }
}

这里的问题是这一行:

ManagementBaseObject outParams = rename.InvokeMethod("Rename", inParams, methodOptions);

方法参数无效。我知道您必须以管理员身份运行它才能执行任何操作,但我只想让它工作。

4

0 回答 0