Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. No WMI query results from code, but results from WMIC?

No WMI query results from code, but results from WMIC?

Scheduled Pinned Locked Moved C#
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bbranded
    wrote on last edited by
    #1

    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 :^)

    B 1 Reply Last reply
    0
    • B bbranded

      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 :^)

      B Offline
      B Offline
      bbranded
      wrote on last edited by
      #2

      bump :rolleyes:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups