erifash Posted November 5, 2005 Posted November 5, 2005 (edited) I have submitted this function to the Standard UDF Library and Jos. I have created a function that will get a process name out of a PID. It is called _ProcessGetName(). This function is useful when you use WinGetProcess() since it only returns a PID. I am thinking about submitting this to the Standard UDF Library but I need someone to review it. Here is the function documentation: ;=============================================================================== ; ; Description - Returns a string containing the process name that belongs to a given PID. ; ; Syntax - _ProcessGetName( $iPID ) ; ; Parameters - $iPID - The PID of a currently running process ; ; Requirements - None. ; ; Return Values - Success - The name of the process ; Failure - Blank string and sets @error ; 1 - Process doesn't exist ; 2 - Error getting process list ; 3 - No processes found ; ; Author(s) - Erifash <erifash [at] gmail [dot] com>, Wouter van Kesteren. ; ; Notes - Supplementary to ProcessExists(). ; ;=============================================================================== The UDF is attached. If anyone is interested please tell me what you think of it. Thanks! process.au3 Edited December 3, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
erifash Posted November 5, 2005 Author Posted November 5, 2005 Hm? Anyone? My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
erifash Posted November 9, 2005 Author Posted November 9, 2005 Okay, I fixed a small variable error. Does anyone think it could be useful? Here is an example: Run("notepad.exe") WinWaitActive("Untitled - Notepad", "") $pid = WinGetProcess("Untitled - Notepad", "") $name = _ProcessGetName($pid) MsgBox(0, "Notepad - " & $pid, $name) My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
w0uter Posted November 9, 2005 Posted November 9, 2005 (edited) looks good, modded it if you dont mind expandcollapse popupFunc _ProcessGetNameE($iPID) If Not ProcessExists($iPID) Then SetError(1) Return "" EndIf Local $aProcesses = ProcessList(), $sProcess = "" If @error Or Not IsArray($aProcesses) Then SetError(2) Return "" EndIf For $i = 1 To $aProcesses[0][0] If $aProcesses[$i][1] = $iPID Then $sProcess = $aProcesses[$i][0] ExitLoop EndIf Next If $sProcess = "" Then SetError(3) Return $sProcess EndFunc ;==>_ProcessGetNameE Func _ProcessGetNameW($i_PID) If Not ProcessExists($i_PID) Then SetError(1) Return '' EndIf Local $a_Processes = ProcessList() If Not @error Then For $i = 1 To $a_Processes[0][0] If $a_Processes[$i][1] = $i_PID Then Return $a_Processes[$i][0] Next EndIf SetError(1) Return '' EndFunc ;==>_ProcessGetNameW ProcessSetPriority(@autoitpid, 5) $i_PID = Run("notepad.exe") ProcessWait($i_PID) Bench($i_PID);benchmarks a real pid Bench(-1);benchmarks a fake pid ProcessClose($i_PID) Func Bench($pid) $ea = 0 $wa = 0 $wouter = 0 For $i = 1 To 1000 $e = TimerInit() $name = _ProcessGetNameE($pid) $e = TimerDiff($e) $w = TimerInit() $name = _ProcessGetNameW($pid) $w = TimerDiff($w) If $e > $w Then $wouter += 1 $ea += $e $wa += $w Next ConsoleWrite('Wouter: ' & $wouter & ' - ' & $wa & @LF) ConsoleWrite('Erifash: ' & 1000 - $wouter & ' - ' & $ea & @CRLF) EndFunc ;==>Bench Edited November 9, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
erifash Posted November 9, 2005 Author Posted November 9, 2005 Thank you, that is faster! I have updated it with your code and added you as one of the authors. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
Valik Posted November 10, 2005 Posted November 10, 2005 (edited) Why not use the Windows API functions OpenProcess(), GetModuleBaseName() and CloseHandle()?Edit: Or GetModuleFileName() to get the full path. Edited November 10, 2005 by Valik
GaryFrost Posted November 10, 2005 Posted November 10, 2005 other ways http://www.autoitscript.com/forum/index.ph...ndpost&p=113711 SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
RickyMartin Posted March 4, 2012 Posted March 4, 2012 On 11/10/2005 at 2:29 AM, 'Valik said: Why not use the Windows API functions OpenProcess(), GetModuleBaseName() and CloseHandle()?Edit: Or GetModuleFileName() to get the full path.YES please!Can I use this as an API call ?!?
Moderators Melba23 Posted March 4, 2012 Moderators Posted March 4, 2012 RickyMartin,Welcome to the AutoIt forum. Did you notice that this thread has been dormant for over 7 years? We do not encourage necroing threads as old as that - the language has developed so much since then that any code is virtually useless. For example, _ProcessGetName is now part of the standard AutoIt UDF library - look under "Process Management". Please do not resurrect any more old threads like this in the future. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts