therks Posted July 20, 2005 Share Posted July 20, 2005 I'm not as hot over this one as I am over my other UDF posted today. This one didn't really require much work, but I found it handy for a script I've been working on. Should be fairly straightforward. Instead of just returning the PID for a window, this returns the process's name (and it also returns the PID in @extended). ;=============================================================================== ; ; Description: _WinGetProcessName - Retrieves the name of the Process associated with a window. ; Syntax: _WinGetProcessName ( $s_Title [, $s_Text ] ) ; Parameter(s): $s_Title - Title of the window to read. ; $s_Text [optional] - Text of the window to read. ; Return Value(s): Success: Returns the name of the Process the window belongs to, ; and sets @extended to the Process ID ; Failure: Returns False, and sets @error to 1 ; Author(s): Saunders (rksaunders@gmail.com) ; ;=============================================================================== Func _WinGetProcessName($s_Title, $s_Text = '') Local $i_PID, $a_ProcList $i_PID = WinGetProcess($s_Title, $s_Text) If $i_PID <> -1 Then $a_ProcList = ProcessList() For $i_For = 1 to $a_ProcList[0][0] If $a_ProcList[$i_For][1] = $i_PID Then SetExtended($i_PID) Return $a_ProcList[$i_For][0] EndIf Next EndIf SetError(1) Return False EndFunc My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
busysignal Posted July 22, 2005 Share Posted July 22, 2005 I'm not as hot over this one as I am over my other UDF posted today. This one didn't really require much work, but I found it handy for a script I've been working on. Should be fairly straightforward. Instead of just returning the PID for a window, this returns the process's name (and it also returns the PID in @extended).This will come in handy to indentify a process, but would be nice to have a _KillWinProcess($i_PID) or Terminate function. Do you have anything like this in your tool box? Cheers.. Link to comment Share on other sites More sharing options...
therks Posted July 22, 2005 Author Share Posted July 22, 2005 (edited) Uhm, wouldn't that be ProcessClose()? Or did you want one where you could specify window title, and it would close the process? That shouldn't be hard... Without testing.. I think this will work: Func _WinProcessClose($s_Title, $s_Text = '') Local $i_PID, $a_ProcList $i_PID = WinGetProcess($s_Title, $s_Text) If $i_PID <> -1 Then $a_ProcList = ProcessList() For $i_For = 1 to $a_ProcList[0][0] If $a_ProcList[$i_For][1] = $i_PID Then Return ProcessClose($i_PID) EndIf Next EndIf SetError(1) Return False EndFunc After some quick testing, seems it works. Edited July 22, 2005 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
busysignal Posted July 25, 2005 Share Posted July 25, 2005 Uhm, wouldn't that be ProcessClose()? Or did you want one where you could specify window title, and it would close the process? That shouldn't be hard...Without testing.. I think this will work:Func _WinProcessClose($s_Title, $s_Text = '') Local $i_PID, $a_ProcList $i_PID = WinGetProcess($s_Title, $s_Text) If $i_PID <> -1 Then $a_ProcList = ProcessList() For $i_For = 1 to $a_ProcList[0][0] If $a_ProcList[$i_For][1] = $i_PID Then Return ProcessClose($i_PID) EndIf Next EndIf SetError(1) Return False EndFuncAfter some quick testing, seems it works.<{POST_SNAPBACK}>I am looking to close a process that may not have a window open, which just might be a ProcessClose() function. I would like to shortcut going to the Windows TaskManager then closing the process that I know has crashed but the {.EXE} is still running for some reason. It is a shortcut-lazy thing.. I will give your code a try, Thanks!! Cheers.. 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