1

I'm trying to run a bat file remotely (from XP to 2003) and running into a problem connecting to any WMI namespace other than cimv2. The code below hits a "Not Found" exception in the "GetMethodParameters" call. But if I replace "directory" with "cimv2", everything is gravy.

ConnectionOptions theConnection = new ConnectionOptions();
theConnection.Username = conDet.User;
theConnection.Password = conDet.Pwd;
theConnection.Impersonation = ImpersonationLevel.Impersonate;

ManagementScope theScope = new ManagementScope(String.Format(@"\\{0}\root\directory", conDet.Server), theConnection);
theScope.Connect();

ManagementClass processClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());

enter code here
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = filename;

ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);

I've checked the security on my machine and the server and the two namespaces have identical security settings. Any ideas what's going on?

Thanks.

1 Answer 1

3

you are using a wrong namespace, the Win32_Process WMI class is defined in root\cimv2.

So you must rewrite your code to

ManagementScope theScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", conDet.Server), theConnection);
2
  • So you're saying that the only namespace I can connect to is cimv2? The rest are off limits?
    – mpeterb
    Mar 14, 2012 at 15:06
  • No i'm not saying that, each time which you establish a WMI connection you must specify a particular namespace (scope). So you can connect to any existing namespace but using different WMI connections.
    – RRUZ
    Mar 14, 2012 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.