Enumerating the If... Then: Scripts

Wednesday, April 15, 2009

C#/.NET: Invoke a WMI method on a remote machine

  private void button7_Click(object sender, EventArgs e)
{

string TargetMachine = textBox2.Text;



ManagementPath path = new ManagementPath("\\\\" + TargetMachine + "\\root\\microsoftdfs");

ManagementScope scope = new ManagementScope(path);

SelectQuery msQuery = new SelectQuery("SELECT * FROM DfsrReplicatedFolderInfo");

ManagementObjectSearcher searchProcedure = new ManagementObjectSearcher(scope, msQuery);



object[] methodArgs = { "" };


foreach (ManagementObject item in searchProcedure.Get())
{
try
{
item.InvokeMethod("GetVersionVector", methodArgs);

foreach (string returned in methodArgs)
{
MessageBox.Show(returned.ToString());
}
}

catch (SystemException excep)
{
MessageBox.Show(excep.Message);
}

}
}