COM Exception

D

dev.manek

Hello,

I am getting irregularly this COM Exception

[CheckCPU] System.Runtime.InteropServices.COMException (0x80041032):
Exception from HRESULT: 0x80041032. at
System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32
errorCode, IntPtr errorInfo) at
System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.GetNextElems()
at
System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()
at HM_Plugin.Module1.checkCPUNow(Int64 CPUThresholdPar)

My Code is

Dim objWMIService, objProcessor, intProcessorUse
Dim QueryString = "SELECT * FROM Win32_Processor" ' WHERE
LoadPercentage > " & CPUThresholdPar
Dim MessageString As String

objWMIService = GetObject("winmgmts:
{impersonationLevel=impersonate,(Security,Backup)}!\\" & Hostname &
"\root\cimv2")
objProcessor = objWMIService.ExecQuery(QueryString)
checkCPUNow = "OK"
For Each intProcessorUse In objProcessor
With intProcessorUse
' Getting this error that's why we have changed
this
' No accessible overloaded 'Math.Round' can be
called without a narrowing conversion
CPUValue = .loadpercentage
If Not IsNothing(CPUValue) Then
CPUValue =
Math.Round(Convert.ToDecimal(CPUValue), 2)
Else
CPUValue = 0
End If
If .LoadPercentage > CInt(CPUThresholdPar) Then
MessageString = "Load Percentage: " &
CPUValue.ToString & "%" & vbCrLf & vbCrLf
MessageString &= "Description: "
& .Description & vbCrLf
MessageString &= "Processor ID: "
& .ProcessorID & vbCrLf
MessageString &= "Status: " & .Status & vbCrLf
MessageString &= "Manufacturer: "
& .Manufacturer & vbCrLf
MessageString &= "Availability: " &
AvailabilityToString(.Availability) & vbCrLf
MessageString &= "Current Clock Speed: "
& .CurrentClockSpeed & " MHz" & vbCrLf
MessageString &= "Maximum Clock Speed: "
& .MaxClockSpeed & vbCrLf
MessageString &= "Level 2 Cache Size: "
& .L2CacheSize & vbCrLf
MessageString &= "Level 2 Cache Speed: "
& .L2CacheSpeed & vbCrLf
MessageString &= "Power Management Supported:
" & .PowerManagementSupported
checkCPUNow = MessageString
'TextFileLogging(Now() & vbCrLf & "checkCPUNow
(load: " & .LoadPercentage & "%)" & vbCrLf &
"-----------------------------")
End If
End With
Next


this exception is coming in XP or Windows 2003
any help will greatly appreciated
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Printing a list box 1

Top