Jump to content



Photo

Proposed UDF: _ProcessGetName()


  • This topic is locked This topic is locked
8 replies to this topic

#1 erifash

erifash

    autoit - think free

  • Active Members
  • PipPipPipPipPipPip
  • 517 posts

Posted 05 November 2005 - 06:49 AM

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! B)

Attached Files


Edited by erifash, 03 December 2005 - 03:25 AM.






#2 erifash

erifash

    autoit - think free

  • Active Members
  • PipPipPipPipPipPip
  • 517 posts

Posted 05 November 2005 - 09:05 PM

Hm? Anyone? B)

#3 erifash

erifash

    autoit - think free

  • Active Members
  • PipPipPipPipPipPip
  • 517 posts

Posted 09 November 2005 - 01:30 AM

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)


#4 w0uter

w0uter

    resreveR nA

  • Active Members
  • PipPipPipPipPipPip
  • 2,262 posts

Posted 09 November 2005 - 03:37 PM

looks good, modded it if you dont mind B)

Plain Text         
Func _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 by w0uter, 09 November 2005 - 03:41 PM.

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

#5 erifash

erifash

    autoit - think free

  • Active Members
  • PipPipPipPipPipPip
  • 517 posts

Posted 09 November 2005 - 10:39 PM

Thank you, that is faster! B) I have updated it with your code and added you as one of the authors.

#6 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 10 November 2005 - 02:29 AM

Why not use the Windows API functions OpenProcess(), GetModuleBaseName() and CloseHandle()?

Edit: Or GetModuleFileName() to get the full path.

Edited by Valik, 10 November 2005 - 02:30 AM.


#7 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 10 November 2005 - 02:37 AM

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.


#8 RickyMartin

RickyMartin

    Seeker

  • Active Members
  • 13 posts

Posted 04 March 2012 - 05:04 PM

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 ?!?

#9 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,343 posts

Posted 04 March 2012 - 05:23 PM

RickyMartin,

Welcome to the AutoIt forum. :oops:

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". :doh:

Please do not resurrect any more old threads like this in the future. :bye:

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users