Jump to content
Sign in to follow this  
jresine

WMI help for disk read / write bytes per sec

Recommended Posts

Hello, is it possible to know via a script or command, to have the percentage of disk usage of a process? thank you in advance.

ps: see image

Capture.JPG

Edited by jresine

Share this post


Link to post
Share on other sites

WMI provides numerous classes that enable performance monitoring, you can read this document.

This class may be of particular interest for you :  Win32_PerfFormattedData_PerfProc_Process

To use WMI with autoIt, just google it, you will find plenty of examples...

Share this post


Link to post
Share on other sites

Okay, so I did a search and modified a piece of code,
there is no script error but the read and write value always remains at 0.
I don't know where my mistake came from, maybe there...

$colProcesses = $objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process Where name = '" & $sProcName & "'")

here is the complete code:

$strComputer = "."
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$process = "explorer.exe"



While 1
    $StartRead = _GetProcTime($process,"r")
    $StartWrite = _GetProcTime($process,"w")
    Sleep(1000)
    $EndRead = _GetProcTime($process,"r")
    $EndWrite = _GetProcTime($process,"w")
    $TotalRead = Int(($EndWrite - $StartWrite))
    $TotalWrite = Int(($EndWrite - $StartWrite))
    ToolTip("explorer.exe" & @CRLF & "Read : " & $TotalRead & " bytes" & @CRLF & "Write: " & $TotalWrite & " bytes", 10, 10, "Read / Write Process per sec")
WEnd

ToolTip("")

Func _GetProcTime($sProcName,$sReadWrite)
    If Not ProcessExists($sProcName) Then Return SetError(1, 0, 0)

    Local $colProcesses, $objProcess, $sngProcessTime

    $colProcesses = $objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process Where name = '" & $sProcName & "'")

        For $objProcess in $colProcesses
            If $sReadWrite == "r" Then $sngProcessTime = $objProcess.IOReadBytesPersec
            If $sReadWrite == "w" Then $sngProcessTime = $objProcess.IOReadWritePersec
        Next

    Return $sngProcessTime
EndFunc

thank you for your help

Share this post


Link to post
Share on other sites

I didn't test your code but it seems right.  But you should check how name (or any other properties) is spelled in a class.  If you had did that, you would have noticed that the ".exe" is removed from the name.  So I would always recommend having those 2 lines after an ExecQuery like :

Local $colItems = $objWMIService.ExecQuery('SELECT ' & $Prop & ' FROM ' & $Class)
  If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object")
  If Not $colItems.count Then Exit MsgBox(0, "", "Not found")

And (very importantly when you start scripting a new class) always display a few instances of the class to see how properties are spelled...Beside that your code is clear.  just always add a few error checking, it will save you a lot of time !

Edited by Nine

Share this post


Link to post
Share on other sites

Ok i found the good WMI : Win32_Process

$strComputer = "."
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

$process = "explorer.exe"



While 1
    $StartRead = _GetProcTime($process,"r")
    $StartWrite = _GetProcTime($process,"w")
    Sleep(1000)
    $EndRead = _GetProcTime($process,"r")
    $EndWrite = _GetProcTime($process,"w")
    $TotalRead = Int(($EndRead - $StartRead) / 1000) / 1000
    $TotalWrite = Int(($EndWrite - $StartWrite) / 1000) / 1000


    ToolTip($process & @CRLF & "Read : " & $TotalRead & " Mo" & @CRLF & "Write: " & $TotalWrite & " Mo", 10, 10, "Read / Write Process per sec")
WEnd

ToolTip("")

Func _GetProcTime($sProcName,$sReadWrite)
    If Not ProcessExists($sProcName) Then Return SetError(1, 0, 0)

    Local $colProcesses, $objProcess, $sngProcessTime

    $colProcesses = $objWMIService.ExecQuery("Select * from Win32_Process Where name = '" & $sProcName & "'")

        For $objProcess in $colProcesses
            If $sReadWrite == "r" Then $sngProcessTime = $objProcess.ReadTransferCount
            If $sReadWrite == "w" Then $sngProcessTime = $objProcess.WriteTransferCount
        Next

    Return $sngProcessTime
EndFunc

it work perfect :)

Edited by jresine

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By shital
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** RunAs(test", @ComputerName, "testinng",2,"wmic product where ""name= '%notepadexamples%'"" call uninstall", @SystemDir & "\wbem", @SW_MAXIMIZE)  it not working 
       
    • By Colduction
      Hi AutoIt Programmers!

      I've seen a code that gives Name of Group by writing it's group's SID, but this one response very slower than Windows Command-Line WMIC
       
      Func _GetLocalGroupName($sSID = 'S-1-5-18') $objWMIService = ObjGet ("winmgmts:\\" & @ComputerName & "\root\cimv2") $colItems = $objWMIService.ExecQuery('SELECT Name FROM Win32_Group where SID="' & $sSID & '"') For $GroupNames in $colItems MsgBox (0,"",$GroupNames.Name) ExitLoop Next EndFunc I don't want call and use any third-party programs even CMD, i just want use from Windows API, netapi32.dll or AutoIt Functions (Standalone).
      Do you have any idea to improve speed/performance of this code? I'll happy of your comments
       
       
       
      ====================== SOLOUTION by @Subz ======================
       
    • By Dwalfware
      HI
      Another head scratched
      Anyone solve how to get the IPV6 from WMI?
      I followed the usual SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID='" & GUICtrlRead($cboAdapters) & "'
      get the index 
      port it to 
      Local $query = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 )
      All i can see is IPv4 addresses
      My question is is there another place the IPv6 information is hiding? I configured my LAN with IPV6 and my wireless with IPv4 so I can see what shows.
      Thanks in Advance.
      PS. I did try google
       
    • By Dwalfware
      Hi Folks
      Can not get my head around this one.
      This function gets the DNS object s
      If you have two DNS entries fine. but if you have only one! Trouble
      $objItem.DNSServerSearchOrder[0] = Primary DNS
      $objItem.DNSServerSearchOrder[1] = Secondry DNS not always there. I need a way to return 0 if not there or the IP if its there.
      Or is there a way to tell how many objects there are in the "[?]"
      I'm terrible at WMI errors, thanks for help in advance.
      Func _GETcurrentNICinfo2() $oErrors = ObjEvent("AutoIt.Error", "Error_Handle") Local $DnsSecondry Local $objWMIService = ObjGet( "winmgmts:\\" & @ComputerName & "\root\CIMV2" ) Local $query = $objWMIService.ExecQuery("SELECT DNSServerSearchOrder FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 ) If @error Then Return 0 If NOT IsObj($query) Then Return 0 Else For $objItem In $query Return $objItem.DNSServerSearchOrder[1] next Endif EndFunc  
    • By amin84
      Hello,
      I'm having trouble getting information from Win32_Processor:
      https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-processor
      How does this WMI Query work? Let's say I need to query VMMonitorModeExtensions, Level, ProcessorId, and ProcessorType.
      How would this work?
      Thanks.
×
×
  • Create New...