dabus Posted November 28, 2006 Share Posted November 28, 2006 (edited) Ok, since someone told me he used pv.exe for getting more informations about a process, I made a simple udf to get things done for me.You need this little one to work: http://www.teamcti.com/pview/pv_5_2_2.zipI works as expected on a WinXP pro SP1.Since I think it's quite usefull, I post it here.I hope you find it usefull too. CODEexpandcollapse popup#cs Author: dabus, dabus@gmx.net Script function: Functions that provide process-information Changes: 0.0.1 - a simple bunch of stdout-functions, but it works 0.0.2 - added some calltips 0.0.5 - added documentation 0.0.6 - added @error-feedback 0.0.7 - _ProcessGetTime returns an array now (closer to standards) 0.0.8 - Use a Generic template Note: Replace this sting >>E:\Programme\Smallstuff\ProcessViewer\pv.exe<< with the correct location!!! Please paste this into your calltips.api: _ProcessGetCpu($a[, $b=0]) Returns the cpu-usage for $a. $b=1/0 don't/do delete pv.exe from @Tempdir (required: #include <System.au3>) _ProcessGetMem($a, $b=0) Returns the memory-usage for $a. $b=1/0 don't/do delete pv.exe from @Tempdir (required: #include <System.au3>) _ProcessGetPath($a, $b=0) Returns the complete path for $a. $b=1/0 don't/do delete pv.exe from @Tempdir (required: #include <System.au3>) _ProcessGetPriority2($a, $b=0) Returns the priority for $a. $b=1/0 don't/do delete pv.exe from @Tempdir (required: #include <System.au3>) _ProcessGetTime($a, $b=0) Returns the creation time for $a. $b=1/0 don't/do delete pv.exe from @Tempdir (required: #include <System.au3>) _ProcessGetUser($a, $b=0) Returns the user running $a. $b=1/0 don't/do delete pv.exe from @Tempdir (required: #include <System.au3>) _ProcessGetVersion($a, $b=0) Returns the version for $a. $b=1/0 don't/do delete pv.exe from @Tempdir (required: #include <System.au3>) #ce #include-once #include <Constants.au3> ;=============================================================================== ; ; Function Name: _ProcessGetCpu($a, $b=0) ; Description: Get the cpu-usage for a specific application ; Parameter(s): $a=application-name, $b=1/0 don't/do delete pv.exe from @Tempdir ; Requirement(s): AutoIt3 Beta & process viewer from http://www.teamcti.com/pview/pv_5_2_2.zip ; Return Value(s): On Success - Returns the cpu-usage ; On Failure - Empty string, @error=1 ; Author(s): dabus ; ;=============================================================================== Func _ProcessGetCpu($a, $b=0) $Output=ProcessGetGeneric($a, $b, 'c') SetError(@error) Return $Output EndFunc ;=============================================================================== ; ; Function Name: _ProcessGetMem($a, $b=0) ; Description: Get the Memory-usage for a specific application ; Parameter(s): $a=application-name, $b=1/0 don't/do delete pv.exe from @Tempdir ; Requirement(s): AutoIt3 Beta & process viewer from http://www.teamcti.com/pview/pv_5_2_2.zip ; Return Value(s): On Success - Returns the memory-usage ; On Failure - Empty string, @error=1 ; Author(s): dabus ; ;=============================================================================== Func _ProcessGetMem($a, $b=0) $Output=ProcessGetGeneric($a, $b, 'm') SetError(@error) Return $Output EndFunc ;=============================================================================== ; ; Function Name: _ProcessGetPath($a, $b=0) ; Description: Get complete path for a specific application ; Parameter(s): $a=application-name, $b=1/0 don't/do delete pv.exe from @Tempdir ; Requirement(s): AutoIt3 Beta & process viewer from http://www.teamcti.com/pview/pv_5_2_2.zip ; Return Value(s): On Success - Returns the path ; On Failure - Empty string, @error=1 ; Author(s): dabus ; ;=============================================================================== Func _ProcessGetPath($a, $b=0) $Output=ProcessGetGeneric($a, $b, 'f') SetError(@error) Return $Output EndFunc ;=============================================================================== ; ; Function Name: _ProcessGetPriority2($a, $b=0) ; Description: Get the priority for a specific application ; Parameter(s): $a=application-name, $b=1/0 don't/do delete pv.exe from @Tempdir ; Requirement(s): AutoIt3 Beta & process viewer from http://www.teamcti.com/pview/pv_5_2_2.zip ; Return Value(s): On Success - Returns the priority ; On Failure - Empty string, @error=1 ; Author(s): dabus ; ;=============================================================================== Func _ProcessGetPriority2($a, $b=0) $Output=ProcessGetGeneric($a, $b, 'p') SetError(@error) Return $Output EndFunc ;=============================================================================== ; ; Function Name: _ProcessGetTime($a, $b=0) ; Description: Get the creation time for a specific application ; Parameter(s): $a=application-name, $b=1/0 don't/do delete pv.exe from @Tempdir ; Requirement(s): AutoIt3 Beta & process viewer from http://www.teamcti.com/pview/pv_5_2_2.zip ; Return Value(s): On Success - Returns the time as an array, starting with 1 ! ; On Failure - Empty array, @error=1 ; Author(s): dabus ; ;=============================================================================== Func _ProcessGetTime($a, $b=0) If Not FileExists(@TempDir&'\pv.exe') Then FileInstall ('E:\Programme\Smallstuff\ProcessViewer\pv.exe', @TempDir) $Output=PipeOne(@TempDir&'\pv.exe ' & $a &' -o"%d') If $b=0 Then FileDelete(@TempDir&'\pv.exe') If StringLen($Output)<>0 Then $Output=StringSplit($Output, ' ') $Date=StringSplit($Output[1], '.') $Time=StringSplit($Output[2], ':') $Output=StringSplit($Date[1]&'|'&$Date[1]&'|'&$Date[1]&'|'&$Time[1]&'|'&$Time[2], '|') Else Dim $Output[4] EndIf If StringLen($Output[1])=0 Then SetError(1) Else SetError(0) EndIf Return $Output EndFunc ;=============================================================================== ; ; Function Name: _ProcessGetUser($a, $b=0) ; Description: Get the user running a specific application ; Parameter(s): $a=application-name, $b=1/0 don't/do delete pv.exe from @Tempdir ; Requirement(s): AutoIt3 Beta & process viewer from http://www.teamcti.com/pview/pv_5_2_2.zip ; Return Value(s): On Success - Returns the username ; On Failure - Empty string, @error=1 ; Author(s): dabus ; ;=============================================================================== Func _ProcessGetUser($a, $b=0) $Output=ProcessGetGeneric($a, $b, 'u') SetError(@error) Return $Output EndFunc ;=============================================================================== ; ; Function Name: _ProcessGetVersion($a, $b=0) ; Description: Get the version for a specific application ; Parameter(s): $a=application-name, $b=1/0 don't/do delete pv.exe from @Tempdir ; Requirement(s): AutoIt3 Beta & process viewer from http://www.teamcti.com/pview/pv_5_2_2.zip ; Return Value(s): On Success - Returns the version ; On Failure - Empty string, @error=1 ; Author(s): dabus ; ;=============================================================================== Func _ProcessGetVersion($a, $b=0) $Output=ProcessGetGeneric($a, $b, 'v') SetError(@error) Return $Output EndFunc ;=============================================================================== ; ; Function Name: PipeOne($a) ; Description: Returns the first line of stdout from an application ; Parameter(s): $a=application-name ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns the line ; On Failure - Empty string ; Author(s): dabus ; ;=============================================================================== Func PipeOne($a) Local $file, $log, $line, $output='' $log=Run ( @ComSpec & ' /c ' & $a, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD ) While 1 $line = StdoutRead($log) If @error Then ExitLoop $output=$line ExitLoop Wend $output=StringReplace($output, @CR, '') $output=StringReplace($output, @LF, '') Return($output) EndFunc ;=============================================================================== ; ; Function Name: PipeOne($a) ; Description: Generic function for pv ; Parameter(s): $a=application-name ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns the line ; On Failure - Empty string ; Author(s): dabus ; ;=============================================================================== Func ProcessGetGeneric($a, $b, $c=0) If Not FileExists(@TempDir&'\pv.exe') Then FileInstall ('E:\Programme\Smallstuff\ProcessViewer\pv.exe', @TempDir) $Output=PipeOne(@TempDir&'\pv.exe ' & $a &' -o"%'&$c) If $b=0 Then FileDelete(@TempDir&'\pv.exe') If StringLen($Output)=0 Then SetError(1) Else SetError(0) EndIf Return $Output EndFunc Edited November 28, 2006 by dabus Link to comment Share on other sites More sharing options...
tazlikesrobots Posted December 20, 2006 Share Posted December 20, 2006 Just what I was looking for! Thanks for posting this Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now