topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday March 19, 2024, 3:12 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FARRCloseSelProc -- FARR helper tool closes process matching selected filename  (Read 9610 times)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
FARRCloseSelProc is a FARR helper tool that closes a process that matches the filename of the file that is selected in Explorer.

This is useful if you work on some code that you need to repeatedly compile, run and later close the process of before the next test run. But it can also be used to quickly close a process that you know the name of.

Setup:
1 paste the code into a text editor and save as FARRCloseSelProc.ahk and then compile it (you need http://ahkscript.org/ for that).
2 store the compiled FARRCloseSelProc.exe in some folder
3 create a FARR alias like this

alias name:
proc close
regex pattern:
^proc(?: |)(.*|)$
result box:
CloseSelProc $$1| C:\some\folder\FARRCloseSelProc.exe $$1 %LASTHWND%

To use it open Explorer and select a file you want to close a matching process for. For example select the file program.exe if you want to close the process program.exe . Press your FARR hotkey, type "proc" and when the alias shows press enter.
To use it by typing a process name press your FARR hotkey, type "proc program.exe" and press enter.

Note:
- The typed process name must match exactly. It must not have any spaces in the name.
- If there are multiple processes with that name only the first one detected by autohotkey will be closed.

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force

x = %1%  ;hwnd parameter from FARR or exact name of a process from FARR
y = %2%  ;hwnd (if first param is exact name)

;FARRCloseSelProc -- a helper tool for FARR
;This tool is made to be run from a FARR alias.

if x =
 exitapp
if y ;filename mode
 splitpath, x, pname,,pext
else ;HWND mode
{
WinGetClass, xclass, ahk_id %x%
if xclass != CabinetWClass  ;exit if not Explorer win
 exitapp
WinActivate, ahk_id %x%,
ifwinNotactive, ahk_id %x%
 exitapp
clip := ClipBoardAll 
clipboard =
send ^c   ;copy
clipwait, 2
if errorlevel != 0
 exitapp
Loop, Parse, clipboard, `n, `r
{
p := a_loopfield
break
}
clipboard := clip ;restore
if InStr( FileExist(p), "D")
 exitapp
splitpath, p, pname,,pext
}

if (pext != "exe")
 exitapp

Process, close, %pname%
Loop, 10
{
Process, Exist, %pname%
if errorlevel = 0
break
sleep 100
}
Process, Exist, %pname%
if errorlevel = 0
 tooltip, Closed process %pname%
else
 tooltip, ERROR. Process %pname% still running.
sleep 2000
exitapp

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Awesome, thanks for sharing!!  :Thmbsup: