Basically I am 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");
That last line, where I call a method on proc, causes this InvalidOperationException... doesn't tell me too much :( I get the same result when calling other methods on proc, such as GetInstances(). When debugging through the code, it does appear that I can connect to the remote machine successfully.
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)