المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : No WMI query results from code, but results from WMIC?



C# Programming
03-31-2009, 11:11 PM
Hello,

I'm having a very strange problem within c# that when I attempt to
query for the list of ReplicationGroupName in DFS, I do not receive
any information; however when I run the same query using WMIC, I get
results.

Here is my c# code ("TargetMachine" being a DFS member server)

System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\\\" + TargetMachine + "\\root\\microsoftdfs");
oMs.Connect();

System.Management.ObjectQuery oQuery = newSystem.Management.ObjectQuery("SELECT ReplicationGroupName FROM DfsrReplicationGroupConfig");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);

foreach (var item in oSearcher.Get())
{
MessageBox.Show(item.ToString());
}


The following works:
WMIC /node:"dynamic-dc01" /namespace:\\root\microsoftdfs path DfsrReplicationGroupConfig get ReplicationGroupName


Why would the C# code not work?


Thanks very much,

Matt Brown http://www.barakasoft.com/script/Forums/Images/smiley_sniff.gif