The System.Management class uses WMI (windows Management Instrumentation) to fetch system information. WMI can fail sometimes, making the calls throw ManagementException.
Is there an alternative to WMI? I do not need much really; here is the CPU information I need:
Private Sub GetNumberOfProcessors()
For Each item In New System.Management.ManagementObjectSearcher("SELECT NumberOfProcessors FROM Win32_ComputerSystem").Get
_NumberOfPhysicalProcessors = CInt(item("NumberOfProcessors"))
Next
For Each item In New System.Management.ManagementObjectSearcher("SELECT NumberOfCores,NumberOfLogicalProcessors FROM Win32_Processor").Get
_NumberOfPhysicalCores = CInt(item("NumberOfCores"))
_NumberOfLogicalCores = CInt(item("NumberOfLogicalProcessors"))
Next
End Sub
If not, I suppose catching the exception and use System.Environment.ProcessorCount as a fall back when that happens could be a worst-case scenario viable option.
EDIT: it seems System.Environment.ProcessorCount is not an option after all, as it relies on WMI too.