C# WMI Connection
-
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. -
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.Hi, I have a similar problem. Did you solve this? In that case I would really appreciate your help. /M