InvalidOperationException when calling methods on a WMI object

Basically, I'm new to WMI, and I can't figure out what I am missing here, or how to debug this ...

    ConnectionOptions connectOptions = new ConnectionOptions();
    connectOptions.Username = user;
    connectOptions.Password = password;
    machine = "remoteMachine.com";

    ManagementScope scope = new ManagementScope(
        @"\\" + machine + @"\root\cimv2",
        connectOptions);

    scope.Connect();

    ManagementPath path = new ManagementPath(@"\\" + machine + @"\root\cimv2\Win23_Process");

    ManagementClass proc = new ManagementClass(scope, path, new ObjectGetOptions());

    ManagementBaseObject args = proc.GetMethodParameters("Create");

This last line, in which I call the proc method, throws this InvalidOperationException ... does not tell me too much :( I get the same result when other methods in proc are called, such as GetInstances (). When debugging through the code, it looks like I can successfully connect to a remote machine.

System.InvalidOperationException was unhandled
  Message="Operation is not valid due to the current state of the object."
  Source="System.Management"
  StackTrace:
       at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass)
       at System.Management.ManagementObject.GetMethodParameters(String methodName)
+3
source share
1 answer

, , . Win23_Process, Win32_Process. Create Win32_Process , command-line, directory ..

+2

Source: https://habr.com/ru/post/1719342/


All Articles