View details as task manager RRS feed

  • Question

  • How can I get the details for the background process as shown in task manager with VB?

    P.S. Include CPU usage and etc.

    • Edited by TheAries Wednesday, September 26, 2018 6:41 AM Add a tag for VB
    Wednesday, September 26, 2018 6:39 AM


All replies

  • Hi,

    determine if a process is a background process

      Public Shared Function hasWindowStyle(ByVal p As Process) As Boolean
            Dim hnd As IntPtr = p.MainWindowHandle
            Dim WS_DISABLED As UInt32 = &H8000000
            Dim GWL_STYLE As Integer = -16
            Dim visible As Boolean = False
            If hnd <> IntPtr.Zero Then
                Dim style As UInt32 = GetWindowLong(hnd, GWL_STYLE)
                visible = ((style And WS_DISABLED) <> WS_DISABLED)
            End If
            Return visible
        End Function
    CPU usage
    Private Shared Sub UsingProcess(ByVal pname As String)
        Using pro = Process.GetProcessesByName(pname)(0)
            Dim interval As Integer = 1000
            Dim prevCpuTime = TimeSpan.Zero
            While True
                Dim curTime = pro.TotalProcessorTime
                Dim value = (curTime - prevCpuTime).TotalMilliseconds / interval / Environment.ProcessorCount * 100
                prevCpuTime = curTime
            End While
        End Using
    End Sub

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, September 26, 2018 8:07 AM
  • How come the result I get for the CPU usage and the data shown in the task manager is totally different?
    Wednesday, September 26, 2018 10:02 AM
  • hello,

    I think you can use WMI queries in timer elapsed event, here is an example of querying management instrumentation to get processor details, this SO thread contains the code you need to query for processor usage, and here is an MSDN Article with an example of connecting WMI and querying it.

    hope it helps,

    • Marked as answer by TheAries Friday, September 28, 2018 3:40 AM
    Wednesday, September 26, 2018 8:17 PM
  • According to what I know, I can get the CPU usage for the device but can I specify it as a background process?
    Thursday, September 27, 2018 1:48 AM