Sign in to follow this  
Followers 0
TarwadaC4

From tip to Progress

3 posts in this topic

hello guys

checkout this Code

$array = ProcessList("explorer.exe")
$iPID = $array[1][1]
$sProcess = $iPID          ;PID number for test process name
;~ $sProcess = "Idle"      ;Other test process names
;~ $sProcess = "_Total"  ;funny one
;~ $sProcess = "ntvdm"    ;DOS process
;~ $sProcess = "AutoIt3"    ;do not assign .exe to process name

While 1
    $iProcessCPU = _ProcessGetCPU($sProcess, 300 )
    $sTip = "Process " & $sProcess & " CPU: " & $iProcessCPU & "%"
    traytip("", $sTip   ,1)
;~  sleep(1000)  ;set your own sleep time for LOOP mode
WEnd

Func _ProcessGetCPU($strProcess = "Idle", $iSampleTime = 10, $sComputerName = @ComputerName)
;~    All Parameters are optional:
;~        - Idle process will be measured if first parameter is not set
;~        - 500 ms is default sample time
;~        - This computer will be measured by default
;~    Process could be string ("Name") or PID number (1234)
;~    When more processes are runing with identical name, then the last opened is measured (use PID for other)
;~    For NORMAL MODE(one time measuring): set Sample value to more than 0 ms
;~                ( average CPU usage will be measured during sleep time within function)
;~    For LOOP MODE (continuous measuring): set Sample value to 0 ms
;~                ( average CPU usage will be measured between two function calls )
;~    Total CPU usage is: ( 100 - _ProcessGetCPU())
;~    Success: Returns process CPU usage in percent
;~            (Sample times below 100ms may return inaccurate results)
;~            (First result in Loop Mode may be inaccurate,
;~             because first call in Loop Mode is only used to trigger counters)
;~    Failure: Returns -1  ( wrong process name or PID )
;~           : Returns -2  ( WMI service not found or Computer not found)
    if $strProcess = "" then $strProcess = "Idle"
    if $iSampleTime = "" AND IsString($iSampleTime) then $iSampleTime = 500
    if $sComputerName = "" then $sComputerName = @ComputerName
    if not IsDeclared("iP1") AND $iSampleTime = 0 then    ;first time in loop mode
        $bFirstTimeInLoopMode = 1
    else
        $bFirstTimeInLoopMode = 0
    endif
    if not IsDeclared("iP1") then
        assign("iP1", 0, 2)  ;forced global declaration first time
        assign("iT1", 0, 2)
    endif

    $objWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2")
    if @error then return -2
    if number($strProcess) then
        $strProcess = " WHERE IDProcess = '" & $strProcess & "'"
    else
        $strProcess = " WHERE Name = '" & $strProcess & "'"
    endif
    if $iSampleTime OR $bFirstTimeInLoopMode = 1 then   ;skip if Loop Mode, but not First time
        $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess)
        For $objItem In $colItems
            $iT1 = $objItem.TimeStamp_Sys100NS
            $iP1 = $objItem.PercentProcessorTime
        next
        if  $objItem = "" then return -1    ;process not found
        sleep($iSampleTime)
    endif

    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess)
    For $objItem In $colItems
        $iP2 = $objItem.PercentProcessorTime
        $iT2 = $objItem.TimeStamp_Sys100NS
    next
    if  $objItem = "" then return -1    ;process not found
    $iPP = ($iP2 - $iP1)
    $iTT = ($iT2 - $iT1)
    if $iTT = 0 Then return 100  ;do not divide by 0
    $iCPU = round( ($iPP/$iTT) * 100, 0)
    $iP1 = $iP2
    $iT1 = $iT2
    Return $iCPU
EndFunc ;==>_ProcessGetCPU() by novaTek ...ver 0.11

ok as you see this will show you your Explorer.exe in tip, im wondering about how to make this show you the CPU Usage in The Progress bar ;)

Lets say we will put the CPU usage in this progress bar :)

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 129, 192, 124)
$Progress1 = GUICtrlCreateProgress(32, 16, 545, 89)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

i hope someone know how to .. :D

Share this post


Link to post
Share on other sites



This is quick solution.

It can be improved to be called according to timers.

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

Global $iProcessCPU_prev = ''

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 129, 192, 124)
$Progress1 = GUICtrlCreateProgress(32, 16, 545, 89)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;~ $array = ProcessList("explorer.exe")
;~ $iPID = $array[1][1]
;~ $sProcess = $iPID          ;PID number for test process name
$sProcess = "Idle"      ;Other test process names
;~ $sProcess = "_Total"  ;funny one
;~ $sProcess = "ntvdm"    ;DOS process
;~ $sProcess = "AutoIt3"    ;do not assign .exe to process name

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
 Case $GUI_EVENT_CLOSE
  Exit
EndSwitch

    $iProcessCPU = _ProcessGetCPU($sProcess, 300 )
If $iProcessCPU <> $iProcessCPU_prev Then
GUICtrlSetData($Progress1, $iProcessCPU)
$iProcessCPU_prev = $iProcessCPU
;~     $sTip = "Process " & $sProcess & " CPU: " & $iProcessCPU & "%"
;~     traytip("", $sTip   ,1)
EndIf
WEnd

Func _ProcessGetCPU($strProcess = "Idle", $iSampleTime = 10, $sComputerName = @ComputerName)
;~    All Parameters are optional:
;~        - Idle process will be measured if first parameter is not set
;~        - 500 ms is default sample time
;~        - This computer will be measured by default
;~    Process could be string ("Name") or PID number (1234)
;~    When more processes are runing with identical name, then the last opened is measured (use PID for other)
;~    For NORMAL MODE(one time measuring): set Sample value to more than 0 ms
;~                ( average CPU usage will be measured during sleep time within function)
;~    For LOOP MODE (continuous measuring): set Sample value to 0 ms
;~                ( average CPU usage will be measured between two function calls )
;~    Total CPU usage is: ( 100 - _ProcessGetCPU())
;~    Success: Returns process CPU usage in percent
;~            (Sample times below 100ms may return inaccurate results)
;~            (First result in Loop Mode may be inaccurate,
;~             because first call in Loop Mode is only used to trigger counters)
;~    Failure: Returns -1  ( wrong process name or PID )
;~           : Returns -2  ( WMI service not found or Computer not found)
    if $strProcess = "" then $strProcess = "Idle"
    if $iSampleTime = "" AND IsString($iSampleTime) then $iSampleTime = 500
    if $sComputerName = "" then $sComputerName = @ComputerName
    if not IsDeclared("iP1") AND $iSampleTime = 0 then    ;first time in loop mode
        $bFirstTimeInLoopMode = 1
    else
        $bFirstTimeInLoopMode = 0
    endif
    if not IsDeclared("iP1") then
        assign("iP1", 0, 2)  ;forced global declaration first time
        assign("iT1", 0, 2)
    endif

    $objWMIService = ObjGet("winmgmts:" & $sComputerName & "rootCIMV2")
    if @error then return -2
    if number($strProcess) then
        $strProcess = " WHERE IDProcess = '" & $strProcess & "'"
    else
        $strProcess = " WHERE Name = '" & $strProcess & "'"
    endif
    if $iSampleTime OR $bFirstTimeInLoopMode = 1 then   ;skip if Loop Mode, but not First time
        $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess)
        For $objItem In $colItems
            $iT1 = $objItem.TimeStamp_Sys100NS
            $iP1 = $objItem.PercentProcessorTime
        next
        if  $objItem = "" then return -1    ;process not found
        sleep($iSampleTime)
    endif

    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_PerfRawData_PerfProc_Process" & $strProcess)
    For $objItem In $colItems
        $iP2 = $objItem.PercentProcessorTime
        $iT2 = $objItem.TimeStamp_Sys100NS
    next
    if  $objItem = "" then return -1    ;process not found
    $iPP = ($iP2 - $iP1)
    $iTT = ($iT2 - $iT1)
    if $iTT = 0 Then return 100  ;do not divide by 0
    $iCPU = round( ($iPP/$iTT) * 100, 0)
    $iP1 = $iP2
    $iT1 = $iT2
    Return $iCPU
EndFunc ;==>_ProcessGetCPU() by novaTek ...ver 0.11
1 person likes this

Share this post


Link to post
Share on other sites

man

you are awesome ;)

:)

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  
Followers 0

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • FroVN
      By FroVN
      Hi, i'm code software listen music on GUI, it's show time playing, hotkey pause/play music, and the last i missing that's the progress to seek the video to hour::ss:( i can't describe exactly, it's like a progress with red color we can backward or fast forward on youtube, i want do the same like that on my gui) i used to use guicreate slider, but it's not good, any idea give me, Tks(sorry for my bad english)
       

    • VIP
      By VIP
      The simple widget shows the percentage of cpu, ram used and the CPU temperature.
      - Sleep Time: 2s for apdate GUI info.
      - Every 30s check, sync and update time for computer.
      - Every 60s auto Reduce Memory.
      - If you want it to run at startup, copy or create shortcut at: "%ProgramData%\Data\Microsoft\Windows\Start Menu\Programs\Startup"
      ;# CPU_Widget_TimeSync.exe ;CRC32: F6640DFA ;MD5: 3283875BA29E7143F1A9AB9018374E08 ;SHA-1: AD85B38BAE15A6962D8E6C1A89B164BE6840C877
      Function code from:
      CPU: 
      RAM:  MemGetStats ( )
      Memory:   _WinAPI_EmptyWorkingSet ()
       
    • RyukShini
      By RyukShini
      #include <ColorConstants.au3>; Including required files #include <GUIConstantsEx.au3> #include <file.au3> #include <Array.au3> #include <string.au3> Example() Func Example() Local $hash Local $hashes = "hash.txt" _FileReadToArray($hashes, $hash) For $i = 1 To UBound($hash) - 500 $hashcheck = $hash[$i] $PDenc = "hash=" & $hashcheck & "&decrypt=Decrypt" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "http://myurl/", False) ; Post url $oHTTP.SetRequestHeader("Host", "myurl") $oHTTP.SetRequestHeader("Connection", "keep-aliveContent-Length: 29") $oHTTP.SetRequestHeader("Cache-Control", "max-age=0") $oHTTP.SetRequestHeader("Origin", "http://myurl") $oHTTP.SetRequestHeader("Upgrade-Insecure-Requests", "1") $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") $oHTTP.SetRequestHeader("Referer", "http://myurl") $oHTTP.SetRequestHeader("Accept-Language", "en-US,en;q=0.8") $oHTTP.Send($PDenc) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status sleep(2000) If $oStatusCode = 503 then MsgBox(4096, "Response code", $oStatusCode) ExitLoop EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) $read = FileRead("Received.html") ;read file if StringInStr($read, "not found") Then ContinueLoop Else ContinueLoop $Datastring = ('</script></div><br/>') $newreadamount = _StringBetween($read, $Datastring, "</b><br/><br/>") ;read title from file $newreadamount[0] = StringReplace($newreadamount[0], '<b>', "") ; taking out the X makes it easier to compare value If @error Then ContinueLoop EndIf $file = FileOpen("decrypted.txt", 1) FileWrite($file, $newreadamount[0] & @CRLF) EndIf Next sleep(2000) EndFunc ;==>Example As you can read my script loads 500 lines of text, lets say I have a list with 10.000 lines
      Is there a way to show a progressbar GUI to show how long in a text file I am?
      I may not know how long a particular .txt file is always so I am thinking I need some sort of algorythm?
      Thanks in advance.
      ( I just got unclear if I actually read 500 lines each attempt or if I start with 500 and add 1 to it each time? )
       
      For $i = 1 To UBound($hash) - 500 ; LIke that ^ For $i = 500 To UBound($hash) - 500 ; or like this^ Thanks a lot.
    • ling3882688
      By ling3882688
      There is an Example called _7ZIPExtractEx_Example_using_Callback.AU3 in the 7-Zip UDF.
      I found a problem. If one file in the 7z archive is too big,the progress  bar will stop for a long time.
      How can I get the exact progress even though there are big files in the archive?
      In other words,how to get the exact extracted file size without delay  ?
      7Zip_UDF.zip