Why are WMI requests so slow sometimes?

I am using the System.Management namespace in .Net to execute various WMI requests on a remote server. In my logs, I see that sometimes requests take 30 or 40 seconds, and other requests complete in less than a second.

When I see these slow requests, I try to connect to the box using wbemtest, but it always connects and quickly executes the request.

Any ideas, pointers, suggestions?

I noticed, looking at System.Management.ManagementScope in the reflector, that it seems to be losing the IWbemServices pointer. It looks like this is a COM interface that needs to call Release (Marshal.ReleaseComObject ()). I am not sure if this is related or not. I connect to many different servers throughout the process.

+7
c # wmi
source share
4 answers

I have the same application that executes multiple WMI requests on all different devices, and I experience the same behavior. Using wbemtest is sometimes faster, but not necessary. I also find that some queries on the same machine behave differently than other queries on the same machine, simply because the other class is queries.

There is a ReturnImmediately property that belongs to the EnumerationOptions class, which can help you get results faster if you get them in one batch rather than listing them over the network.

EnumerationOptions options = new EnumerationOptions(); options.ReturnImmediately = false; 

You can try it and see if it helps. I know that this is not what you want to hear, but my personal opinion is that you cannot do much. You need to write code to solve this problem. The real answer lies somewhere deep in the warmth of DCOM, the WMI protocol, and the WMI repository.

+2
source share

You can try setting the WITHIN field to make sure that this will cause the request to happen earlier. Could you send the request you are using? This can help debug any additional issues.

+2
source share

Is the problem specific to a single window? I once had the same problem with a remote script. I fixed it by restoring the TCP / IP stack to a field, making a remote call.

0
source share

See the WBEM_FLAG_RETURN_IMMEDIATE and WBEM_FLAG_FORWARD_ONLY flags for your language. When using Scriptomatic (MS VBScript's large GUI for creating WMI calls), this option is automatically added as part of the parameters. 48 means WBEM_FLAG_RETURN_IMMEDIATE | WBEM_FLAG_FORWARD_ONLY. VBScript example:

 objWMIService.ExecQuery ("Select * from Win32_NetworkConnection",,48) 

https://msdn.microsoft.com/en-us/library/aa390880(v=vs.85).aspx

0
source share

All Articles