Unicode := A_IsUnicode ? "W" : ""
TH32CS_SNAPPROCESS := 0x00000002
TH32CS_SNAPTHREAD := 0x00000004
CreateToolhelp32Snapshot(Flags, th32ProcessID)
{
return DllCall("CreateToolhelp32Snapshot", "int", Flags, "int", th32ProcessID)
}
Process32First(hSnapshot, pe)
{
global Unicode
return DllCall("Process32First" . Unicode, "int", hSnapshot, "int", pe)
}
Process32Next(hSnapshot, pe)
{
global Unicode
return DllCall("Process32Next" . Unicode, "int", hSnapshot, "int", pe)
}
Thread32First(hSnapshot, te)
{
return DllCall("Thread32First", "int", hSnapshot, "int", te)
}
Thread32Next(hSnapshot, te)
{
return DllCall("Thread32Next", "int", hSnapshot, "int", te)
}
THREAD_SUSPEND_RESUME := 0x0002
OpenThread(DesiredAccess, InheritHandle, ThreadId)
{
return DllCall("OpenThread" , "int", DesiredAccess, "int", InheritHandle, "int", ThreadId)
}
SuspendThread(hThread)
{
return DllCall("SuspendThread", "int", hThread)
}
ResumeThread(hThread)
{
return DllCall("ResumeThread", "int", hThread)
}
CloseHandle(Handle)
{
return DllCall("CloseHandle", "int", Handle)
}
Gui Add, Button, x10 y5 w75 gL_Update, Обновить
Gui Add, Button, x100 y5 w75 gL_Stop, Stop
Gui Add, Button, x200 y5 w75 gL_Start, Start
Gui Add, ListView, x10 y35 r20 w450 -Multi, PID|имя процесса|статус
LV_ModifyCol(1, 50)
LV_ModifyCol(2, 300)
LV_ModifyCol(3, 50)
Update()
Gui Show
return
L_Update:
Update()
return
L_Stop:
Stop()
return
L_Start:
Start()
return
Start()
{
global TH32CS_SNAPTHREAD, THREAD_SUSPEND_RESUME
row := LV_GetNext(0, "Focused")
LV_GetText(id, row)
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, id)
VarSetCapacity(te, 28)
NumPut(28, te, 0)
str := ""
test := Thread32First(hSnapshot, &te)
while test
{
if (id=NumGet(te, 12))
{
hThread := OpenThread(THREAD_SUSPEND_RESUME, 0, NumGet(te, 8))
if (hThread=0)
{
LV_Modify(row, "Col3" , "-1 (" . a_lasterror . ")")
CloseHandle(hSnapshot)
return
}
ret := ResumeThread(hThread)
CloseHandle(hThread)
}
test := Thread32Next(hSnapshot, &te)
}
CloseHandle(hSnapshot)
LV_Modify(row, "Col3" , ret=0 ? 0 : ret-1)
}
Stop()
{
global TH32CS_SNAPTHREAD, THREAD_SUSPEND_RESUME
row := LV_GetNext(0, "Focused")
LV_GetText(id, row)
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, id)
VarSetCapacity(te, 28)
NumPut(28, te, 0)
test := Thread32First(hSnapshot, &te)
while test
{
if (id=NumGet(te, 12))
{
hThread := OpenThread(THREAD_SUSPEND_RESUME, 0, NumGet(te, 8))
if (hThread=0)
{
LV_Modify(row, "Col3" , "-1 (" . a_lasterror . ")")
CloseHandle(hSnapshot)
return
}
ret := SuspendThread(hThread)
CloseHandle(hThread)
}
test := Thread32Next(hSnapshot, &te)
}
CloseHandle(hSnapshot)
LV_Modify(row, "Col3" , ret+1)
}
Update()
{
global TH32CS_SNAPPROCESS
LV_Delete()
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
pesize := A_IsUnicode ? 556 : 296
VarSetCapacity(pe, pesize)
NumPut(pesize, pe, 0)
test := Process32First(hSnapshot, &pe)
while test
{
LV_Add("", NumGet(pe,8), StrGet(&pe+36),"?")
test := Process32Next(hSnapshot, &pe)
}
CloseHandle(hSnapshot)
}
GuiClose:
ExitApp
return