在远程计算机上执行WMI方法 [英] Execute WMI method on remote computer

查看:159
本文介绍了在远程计算机上执行WMI方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试在SCCM 2012中批准客户的远程计算机上执行方法。我有以下代码...

Hi All,

I am trying to execute a method on a remote computer that will approve clients in SCCM 2012. I have the below code...

ManagementObject classInstance =
                    new ManagementObject("\\\\SERVERNAME\\root\\SMS\\SITENAME:SMS_Collection.CollectionID='SMS00001'");

                // Obtain in-parameters for the method
                ManagementBaseObject inParams =
                    classInstance.GetMethodParameters("ApproveClients");

                // Add the input parameters.
                inParams["Approved"] = 1; //Have tried a combination of true/false 1/0
                inParams["ResourceIDs"] = resourceIDS; //This is an int[]

                foreach (var item in inParams.Properties)
                {
                    Console.WriteLine(item.Name);
                }
                
                // Execute the method and obtain the return values.
                ManagementBaseObject outParams =
                    classInstance.InvokeMethod("ApproveClients", inParams, null); 

                // List outParams
                Console.WriteLine("Out parameters:");
                Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);





对于任何看到这个并在网上搜索链接的人来说 - 这是对SCCM 2012 SDK中的代码以及详细说明如何在c#中执行WMI方法的technet文章的改编。



我在代码中包含了一个部分,它将属性打印到控制台(这些属性是 ResourceIDs Approved )。即使没有我设置这些属性的值,它们仍然显示 - 所以我知道方法存在。



然而,当我尝试调用方法时,我收到一条错误消息只是简单地说无效方法即使我知道它存在并且shoudl有效。



我已经使用此代码执行其他方法在我的代码中没有任何问题。



任何人都可以为我解释这个问题,并提出为什么这种方法无效?

我设置管理对象的方式有问题吗?

远程这个特定方法有什么影响吗?

为什么我可以提取方法属性,但后来被告知方法无效?



我期待你的回复!!



谢谢!



To anyone looking at this and searching the web for links - this is an adaptation of the code in the SCCM 2012 SDK and on technet articles detailing how to execute WMI methods in c#.

I have included a section in the code that prints out the properties to the console (these properties are ResourceIDs and Approved). Even without me setting the value of these properties they are still displayed - so i know the method exists.

However when i try and invoke the method I get an error message that simply says "Invalid Method" even though I know it exists and shoudl be valid.

I have used this code to execute other methods in my code with no problem at all.

Can anyone shed any light on this for me and propose why this method could be invalid?
Is there something wrong with the way i am setting up the management objects?
Does the fact that it's remote have any bearing on this particular method?
Why can i extract the method properties but then be told that the method is invalid?

I look forward to your replies!!

Thanks!

推荐答案

我有同样的问题,发现它是一个静态方法。

所以尝试连接到SMS_Collection类而不是特定的实例。
Hi, I had the same issue and found out it is a static method.
So try to connect to the SMS_Collection class instead of a specific instance.


这篇关于在远程计算机上执行WMI方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆