Click here to Skip to main content
15,925,181 members
Home / Discussions / C#
   

C#

 
QuestionInvoking a WMI method on a Remote Machine Pin
bbranded15-Apr-09 6:05
bbranded15-Apr-09 6:05 
Hello,

I am attempting to invoke the GetVersionVector method of the DfsrReplicatedFolderInfo on a remote machine.

After referring to two articles (1, 2) about the subject on InvokeMethod in C#, I have written the following code:


<br />
string TargetMachine = textBox2.Text;<br />
<br />
<br />
System.Management.ManagementScope oMs = new<br />
<br />
System.Management.ManagementScope("\\\\" + TargetMachine + "\\root\\microsoftdfs");<br />
oMs.Connect();<br />
<br />
System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("SELECT * FROM DfsrReplicatedFolderInfo"); //WHERE ReplicationGroupName='" + comboBox6.Text + "'");<br />
<br />
ManagementObjectSearcher oSearcher = new<br />
<br />
ManagementObjectSearcher(oMs, oQuery);<br />
<br />
ManagementObjectCollection MgmtObject = oSearcher.Get();<br />
<br />
<br />
foreach (ManagementObject item in MgmtObject)<br />
{<br />
<br />
    //Get an input parameters object for this method<br />
    //ManagementBaseObject inParams = item.GetMethodParameters("GetVersionVector");<br />
<br />
    //Fill in input parameter values<br />
    //inParams["CommandLine"] = "calc.exe";<br />
<br />
    //Execute the method<br />
    ManagementObject outParams = (ManagementObject)item.InvokeMethod("GetVersionVector", null);<br />
<br />
    //Display results<br />
    //Note: The return code of the method is provided in the "returnValue" property of the outParams object<br />
    MessageBox.Show(outParams.ToString());<br />
}<br />



When attempting to InvokeMethod, the following error is thrown:

Object reference not set to an instance of an object.


If I do away with the cast and use declare outParams as an object instead, i get the same error.


Any input is appreciated,

Matt Brown
AnswerRe: Invoking a WMI method on a Remote Machine Pin
bbranded15-Apr-09 8:22
bbranded15-Apr-09 8:22 
Questionsynchronous and asynchronous communication Pin
yesu prakash15-Apr-09 5:52
yesu prakash15-Apr-09 5:52 
AnswerRe: synchronous and asynchronous communication Pin
0x3c015-Apr-09 6:29
0x3c015-Apr-09 6:29 
GeneralRe: synchronous and asynchronous communication Pin
yesu prakash15-Apr-09 18:08
yesu prakash15-Apr-09 18:08 
QuestionProblem in disabling close button(X) of window. Pin
priyamtheone15-Apr-09 5:25
priyamtheone15-Apr-09 5:25 
AnswerRe: Problem in disabling close button(X) of window. [modified] Pin
DaveyM6915-Apr-09 5:31
professionalDaveyM6915-Apr-09 5:31 
AnswerRe: Problem in disabling close button(X) of window. Pin
agent00zelda15-Apr-09 5:32
agent00zelda15-Apr-09 5:32 
GeneralRe: Problem in disabling close button(X) of window. Pin
priyamtheone15-Apr-09 20:16
priyamtheone15-Apr-09 20:16 
AnswerRe: Problem in disabling close button(X) of window. Pin
Luc 64801115-Apr-09 5:40
Luc 64801115-Apr-09 5:40 
AnswerRe: Problem in disabling close button(X) of window. Pin
DaveyM6915-Apr-09 5:43
professionalDaveyM6915-Apr-09 5:43 
AnswerRe: Problem in disabling close button(X) of window. Pin
PIEBALDconsult15-Apr-09 6:03
mvePIEBALDconsult15-Apr-09 6:03 
NewsRe: Problem in disabling close button(X) of window. Pin
priyamtheone15-Apr-09 21:25
priyamtheone15-Apr-09 21:25 
QuestionSIteMap Pin
kibromg15-Apr-09 4:02
kibromg15-Apr-09 4:02 
AnswerRe: SIteMap Pin
hat_master15-Apr-09 6:04
hat_master15-Apr-09 6:04 
GeneralRe: SIteMap Pin
kibromg15-Apr-09 6:36
kibromg15-Apr-09 6:36 
AnswerRe: SIteMap Pin
hat_master15-Apr-09 7:18
hat_master15-Apr-09 7:18 
GeneralRe: SIteMap Pin
kibromg16-Apr-09 0:54
kibromg16-Apr-09 0:54 
QuestionStopping a Windows Service in a Timely Manner... Pin
agent00zelda15-Apr-09 3:42
agent00zelda15-Apr-09 3:42 
AnswerRe: Stopping a Windows Service in a Timely Manner... Pin
PIEBALDconsult15-Apr-09 6:15
mvePIEBALDconsult15-Apr-09 6:15 
GeneralRe: Stopping a Windows Service in a Timely Manner... Pin
agent00zelda15-Apr-09 7:38
agent00zelda15-Apr-09 7:38 
QuestionNeed a clue with Configuration Sections Pin
Optimus Chaos15-Apr-09 3:28
Optimus Chaos15-Apr-09 3:28 
Questionoverload operator + Pin
al3xutzu0015-Apr-09 2:16
al3xutzu0015-Apr-09 2:16 
AnswerRe: overload operator + Pin
Dino Mulahusic15-Apr-09 2:25
professionalDino Mulahusic15-Apr-09 2:25 
AnswerRe: overload operator + Pin
0x3c015-Apr-09 2:28
0x3c015-Apr-09 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.