Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

workaround: List Processes Running


  • Please log in to reply
4 replies to this topic
Decarlo110
  • Members
  • 303 posts
  • Last active: Feb 12 2006 02:15 AM
  • Joined: 15 Dec 2004
Here is a workaround that lists running processes until the feature gets formally built in.

This program is meant as an aid for scripts which require recognition of other running programs.. normal programs which have windows. If you wish to detect all processes, you can insert a loop which checks up to a maximum PID number, returning the errorLevel if not 0, or just wait til tthe feature gets built-in to AutoHotkey. This program does not detect additional PID's which share identical process names; this limitation stems from the current version of the Process cmd, as of Ahk 1.0.37.2

; ListAllProcesses 1.1
; by Decarlo

^#!p::

SetBatchLines -1
Process, Priority,, H	; High
DetectHiddenWindows, on
SetFormat, Float, 0.3

ExeWin=
ExeSrv=
processList=
winList=

startListProc=%A_TickCount%
Process, exist, system
processList=%processList%%ErrorLevel%`tSystem`r`n`r`n
Process, Exist,		; needs Ahk 1.0.36+
processList=%processList%%ErrorLevel%`tAutoHotkey.exe`r`n
WinGet, Win#, List
Loop %Win#%
{
	winListItem := win#%A_Index%
	winList = %winList%%winListItem%`r`n	; get id's of windows
}
Sort, winList, U
Loop, parse, WinList, `n, `r			; get pid's matching windows
{
	WinGet, PID, PID, ahk_id %A_LoopField%
	PIDList = %PIDList%%PID%`r`n
}
Sort, PIDList, NU
Loop, parse, PIDList, `n, `r
{
	if A_LoopField =
		CONTINUE
	WinGet, processName, ProcessName, ahk_pid %A_LoopField%
	processList=%processList%%A_LoopField%`t%processName%`r`n
}
StringReplace, processList, processList, `r`n	   ; delete blank lines
Sort, processList, N
Loop, %windir%\system32\*.exe			; find system32 folder executables
	ExeWin=%ExeWin%%A_LoopFileName%`r`n
Loop, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Services, 1, 1	; find system services
{
	if A_LoopRegName=ImagePath
	{
		RegRead, itemExe ;, HKEY_LOCAL_MACHINE, %A_LoopRegSubKey%, ImagePath
		ifInString, itemExe, .exe
		{
			StringGetPos, posImage, itemExe, .exe
			StringLen, itemExeLength, itemExe
			offsetExe:=itemExeLength-posImage
			StringGetPos, posSlash, itemExe, \, R, offsetExe
			StringMid, imageExe, itemExe, % posSlash+2, % posImage-posSlash+3
			ExeSrv=%ExeSrv%%imageExe%`r`n
		}
	}
}
Sort, ExeWin, U
Sort, ExeSrv, U
Exe=%ExeWin%%ExeSrv%
Sort, Exe, U
Loop, Parse, Exe, `n, `r		; check active Prog, sys folder executables
{
	Process, exist, %A_LoopField%
	If ErrorLevel <> 0
		processList=%processList%%ErrorLevel%`t%A_LoopField%`r`n
}
Sort, processList, N
Loop, Parse, processList, %A_Tab%`n, `r		; remove semi-duplicates (blank name field)
{
	;msgbox %A_LoopField%
	if A_LoopField is not integer
		Continue
	if A_LoopField <> %A_LoopFieldPrev%
	{
		A_LoopFieldPrev = %A_LoopField%
		Continue
	}
	StringReplace, processList, processList, %A_LoopField%`r`n ;, ReplaceText
	A_LoopFieldPrev = %A_LoopField%
}
timeListProc:=(A_TickCount-startListProc)/1000
Sort, processList, NU
; alternatively, use: ifInString, processList, <processToCheck> , for further operations
Run, Notepad,,, NPid
WinWait, ahk_pid %Npid%
WinSetTitle, ahk_pid %Npid%,, Process List
WinActivate
WinWaitActive,,, 5
if ErrorLevel=1
	Msgbox, The target Notepad window did not respond.
ControlSetText, Edit1, Process Checker: running processes`r`n`r`n0`tSystem Idle Process`r`n%processList%----------`r`n`r`nThe following executables which might not have associated windows`, were checked.`r`nThis program does not detect any other non-window processes.`r`nThis program does not detect additional PID's which share identical process names.`r`n`r`nSystem services:`r`n`r`n%ExeSrv%`r`nSystem32 folder processes:`r`n`r`n%ExeWin%`r`n, ahk_pid %NPid%
Process, Priority,, N		; Normal
msgbox, 4096, note, Done`n`n%timeListProc% sec, 1.2

return

The following link has a good cmd line utility for this purpose:
http://www.autohotke...opic.php?t=1814
1) The Open Source Definition http://www.opensourc...ition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <>

Decarlo110
  • Members
  • 303 posts
  • Last active: Feb 12 2006 02:15 AM
  • Joined: 15 Dec 2004
Updated with the following:

1) removed the time limitation. takes 0.7 sec on my system.
2) can now be used on Win98 and beyond.

See the first post for most recent version.
1) The Open Source Definition http://www.opensourc...ition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <>

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
It looks good.

If the updated version is superior to the first version in every way, you might want to move the updated version into the first post to avoid people trying out the first one only to realize later that there's a newer one. Since this practice also helps conserve the forum's database space, it would help if you could also do it for any other long scripts you have posted, such as 110.1 Delete Empty Folders

Thanks for sharing and improving these useful scripts. :)

Decarlo110
  • Members
  • 303 posts
  • Last active: Feb 12 2006 02:15 AM
  • Joined: 15 Dec 2004

you might want to move the updated version into the first post to avoid people trying out the first one only to realize later that there's a newer one.


Good idea :idea:
i'll make it normal practice from now on.

edit: i couldn't delete the 2nd one in this thread because it wasn't the newest post anymore.
1) The Open Source Definition http://www.opensourc...ition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <>

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
You could just end the second one to say something to the effect that "the post at the top has been updated with the following changes".