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 DirtyJohny
      Hi everyone.Need rewrite this function how in еxample.
      Original:
      #RequireAdmin #NoTrayIcon Opt("MustDeclareVars",1) Func _a() Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _ &"authenticationLevel=Pkt}!\\"& _ @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _ ('SELECT * FROM WmiMonitorID'), _ $lll,$sll,$sss="",$lsl,$lls,$i,$z For $z In $lss $lsl=$z.UserFriendlyName For $i=0 To Ubound($lsl)-1 if ($lsl[$i]) Then $lll&=Chr($lsl[$i]) Next $lls=$z.SerialNumberID For $i=0 To Ubound($lls)-1 if ($lls[$i]) Then $sll&=Chr($lls[$i]) Next $sss&="Model"&@TAB&@TAB&": "&$lll&@CR&"Serial Number"&@TAB&": "&$sll&@CR&@CR $lll="" $sll="" Next MsgBox(262144,'Monitors '&$lss.Count,$sss&" "&@CR) $lss=Null $sls=Null EndFunc _a() Example:
      Func _InfoPC() Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2') Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30) If IsObj($ObjService) Then For $objItemMB In $ObjMB $sInfo &= @TAB & 'Motherboard: ...... ' & $objItemMB.Product & @CRLF I'm beginner in this sphere and need  you all speak easy and simply because i'm Russian.Thanks)
    • By jguinch
      Hello.
      I did create these few functions several months ago. I post here, if it can interest someone.
      These functions based on WMI queries allow you to manage printers : add / delete printer, driver, port, or obtain configuration, set default printer ... I let you discover it with the code.

       
      Here is the list of the available functions :
      _Printmgr_AddLocalPort
      _Printmgr_AddLPRPort
      _PrintMgr_AddPrinter
      _PrintMgr_AddPrinterDriver
      _PrintMgr_AddTCPIPPrinterPort
      _PrintMgr_AddWindowsPrinterConnection
      _PrintMgr_CancelAllJobs
      _Printmgr_EnumPorts
      _PrintMgr_EnumPrinter
      _PrintMgr_EnumPrinterConfiguration
      _PrintMgr_EnumPrinterDriver
      _PrintMgr_EnumPrinterProperties
      _PrintMgr_EnumTCPIPPrinterPort
      _Printmgr_Pause
      _Printmgr_PortExists
      _Printmgr_PrinterExists
      _Printmgr_PrinterSetComment
      _Printmgr_PrinterSetDriver
      _Printmgr_PrinterSetPort
      _Printmgr_PrinterShare
      _Printmgr_PrintTestPage
      _PrintMgr_RemoveLocalPort
      _PrintMgr_RemoveLPRPort
      _PrintMgr_RemovePrinter
      _PrintMgr_RemovePrinterDriver
      _PrintMgr_RemoveTCPIPPrinterPort
      _PrintMgr_RenamePrinter
      _Printmgr_Resume
      _PrintMgr_SetDefaultPrinter
       
      And some examples :
      #include <Array.au3> #include "PrintMgr.au3" _Example() Func _Example() ; Remove a printer called "My old Lexmark printer" : _PrintMgr_RemovePrinter("My old Lexmark printer") ; Remove the driver called "Lexmark T640" : _PrintMgr_RemovePrinterDriver("Lexmark T640") ; Remove the TCP/IP printer port called "TCP/IP" _PrintMgr_RemoveTCPIPPrinterPort("MyOLDPrinterPort") ; Add a driver, called "Samsung ML-451x 501x Series", and driver inf file is ".\Samsung5010\sse2m.inf" _PrintMgr_AddPrinterDriver("Samsung ML-451x 501x Series", "Windows NT x86", @ScriptDir & "\Samsung5010", @ScriptDir & "\Samsung5010\sse2m.inf") ; Add a TCP/IP printer port, called "MyTCPIPPrinterPort", with IPAddress = 192.168.1.10 and Port = 9100 _PrintMgr_AddTCPIPPrinterPort("MyTCPIPPrinterPort", "192.168.1.10", 9100) ; Add a printer, give it the name "My Printer", use the driver called "Samsung ML-451x 501x Series" and the port called "MyTCPIPPrinterPort" _PrintMgr_AddPrinter("My Printer", "Samsung ML-451x 501x Series", "MyTCPIPPrinterPort") ; Set the printer called "My Printer" as default printer _PrintMgr_SetDefaultPrinter("My Printer") ; Connect to the shared printer "\\192.168.1.1\HPDeskjetColor") _PrintMgr_AddWindowsPrinterConnection("\\192.168.1.1\HPDeskjetColor") ; List all installed printers Local $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) ; List all printers configuration Local $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration() _ArrayDisplay($aPrinterConfig) ; List all installed printer drivers Local $aDriverList = _PrintMgr_EnumPrinterDriver() _ArrayDisplay($aDriverList) ; Retrieve the printer configuration for the printer called "Lexmark T640" $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration("Lexmark T640") _ArrayDisplay($aPrinterConfig) ; Add a local printer port (for a file output) _PrintMgr_AddLocalPort("c:\temp\output.pcl") ; Remove the local port _PrintMgr_RemoveLocalPort("c:\temp\output.pcl") EndFunc ;==>_Example Download link :
      PrintMgr.au3
      PrintMgr_Example.au3
    • 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
       
×
×
  • Create New...