1
我試圖遠程運行bat文件(從XP到2003),並遇到連接到除cimv2之外的任何WMI命名空間的問題。下面的代碼在「GetMethodParameters」調用中遇到「Not Found」異常。但如果我用「cimv2」替換「目錄」,一切都是肉汁。WMI命名空間「未找到」
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);
我檢查了我的計算機和服務器上的安全和兩個命名空間具有相同的安全設置。任何想法發生了什麼?
謝謝。
所以你說,唯一的命名空間,我可以連接到是CIMV2?其餘的都沒有限制? – mpeterb 2012-03-14 15:06:50
不,我不是這麼說的,每次建立WMI連接時,都必須指定一個特定的名稱空間(作用域)。因此,您可以連接到任何現有的名稱空間,但使用不同的WMI連接。 – RRUZ 2012-03-14 15:09:03
我明白了,非常感謝。 – mpeterb 2012-03-14 15:16:54