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
  1. Home
  2. General Programming
  3. C#
  4. C# WMI Connection

C# WMI Connection

Scheduled Pinned Locked Moved C#
csharpsysadminhelp
2 Posts 2 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.
  • S Offline
    S Offline
    Shaps
    wrote on last edited by
    #1

    Hello everybody, I have a problem while trying to make a monitoring server with WMI. I have arround 400 check to do on 15 servers. After 5 minutes a lot of port on my server are un TIME_WAIT state, so I get a RCP-server not avalaible :(. I've reduce the TIME_WAIT timeout but nothing change... Is there a way to close the WMI connection, I'm using ManagementScope... Here's a part of my code public WMIRequest(string Username, string Password, string IP) { aConnectionOptions = new ConnectionOptions(); aConnectionOptions.EnablePrivileges = true; aConnectionOptions.Username = Username; aConnectionOptions.Password = Password; //aConnectionOptions.Timeout = new TimeSpan(0,0,30); this.IP = IP; } public bool Connect() { aManagementScope = new ManagementScope(@"\\"+ IP + @"\root\cimv2", aConnectionOptions); aManagementScope.Connect(); return aManagementScope.IsConnected; } public string Request(string Request) { aObjectQuery = new ObjectQuery(Request); aManagementObjectSearcher = new ManagementObjectSearcher(aManagementScope, aObjectQuery); aManagementObjectCollection = aManagementObjectSearcher.Get(); string Result = ""; foreach(ManagementObject aManagementObject in aManagementObjectCollection ) { if(aManagementObjectCollection.Count > 1) Result += "|#*#|"; foreach (System.Management.PropertyData aPropertyData in aManagementObject.Properties) { if(aManagementObject.Properties.Count > 1) Result += "|#|"; Result += aPropertyData.Name + "|*|" + System.Convert.ToString(aManagementObject[aPropertyData.Name]); } } return Result; } I hope somebody has already resolved this problem... Thank you Nicolas.

    M 1 Reply Last reply
    0
    • S Shaps

      Hello everybody, I have a problem while trying to make a monitoring server with WMI. I have arround 400 check to do on 15 servers. After 5 minutes a lot of port on my server are un TIME_WAIT state, so I get a RCP-server not avalaible :(. I've reduce the TIME_WAIT timeout but nothing change... Is there a way to close the WMI connection, I'm using ManagementScope... Here's a part of my code public WMIRequest(string Username, string Password, string IP) { aConnectionOptions = new ConnectionOptions(); aConnectionOptions.EnablePrivileges = true; aConnectionOptions.Username = Username; aConnectionOptions.Password = Password; //aConnectionOptions.Timeout = new TimeSpan(0,0,30); this.IP = IP; } public bool Connect() { aManagementScope = new ManagementScope(@"\\"+ IP + @"\root\cimv2", aConnectionOptions); aManagementScope.Connect(); return aManagementScope.IsConnected; } public string Request(string Request) { aObjectQuery = new ObjectQuery(Request); aManagementObjectSearcher = new ManagementObjectSearcher(aManagementScope, aObjectQuery); aManagementObjectCollection = aManagementObjectSearcher.Get(); string Result = ""; foreach(ManagementObject aManagementObject in aManagementObjectCollection ) { if(aManagementObjectCollection.Count > 1) Result += "|#*#|"; foreach (System.Management.PropertyData aPropertyData in aManagementObject.Properties) { if(aManagementObject.Properties.Count > 1) Result += "|#|"; Result += aPropertyData.Name + "|*|" + System.Convert.ToString(aManagementObject[aPropertyData.Name]); } } return Result; } I hope somebody has already resolved this problem... Thank you Nicolas.

      M Offline
      M Offline
      Mattias Olgerfelt
      wrote on last edited by
      #2

      Hi, I have a similar problem. Did you solve this? In that case I would really appreciate your help. /M

      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