Jump to content

Process Info using objects and wmi


GaryFrost
 Share

Recommended Posts

#include <Array.au3>

$colItems = ""
$strComputer = "localhost"

$a_ProcessInfo = _GetProcessInfo($strComputer)
For $i = 1 To $a_ProcessInfo[0]
    $process = StringSplit($a_ProcessInfo[$i], "|")
    MsgBox(0, "Process Info", "Name: " & $process[1] & @CRLF & _
            "PID: " & $process[2] & @CRLF & _
            "Memory: " & $process[3])
Next

Func _GetProcessInfo($strComputer)
    Dim $a_items[1]
    Const $wbemFlagReturnImmediately = 0x10
    Const $wbemFlagForwardOnly = 0x20
    
    Dim $a_items[1], $objWMIService, $colItems = ""
    $objWMIService = ObjGet ("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery ("SELECT Name,IDProcess,WorkingSet FROM Win32_PerfFormattedData_PerfProc_Process", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj ($colItems) Then
        For $objItem In $colItems
            If $objItem.Name <> "_Total" Then
                ReDim $a_items[UBound($a_items) + 1]
                $a_items[UBound($a_items) - 1] = $objItem.Name & "|" & $objItem.IDProcess & "|" & $objItem.WorkingSet
                $a_items[0] = $a_items[0] + 1
            EndIf
        Next
    EndIf
    _ArraySort($a_items)
    Return $a_items
EndFunc  ;==>_GetProcessInfo

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 19 years later...

This is a REALLY good function! Thank you for writing it! All I did was to just dump it right in to the program I am writing. (Which is just so-so. :-) )

Link to comment
Share on other sites

You did notice that you necro an 19 years old thread, did you 🤔

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...