Hacker’s Corner: A Windows Task Killer
Vector 10:2, page 126
The text of this article is not yet online.
Read it in the PDF of the issue, page 126
Unedited OCR text, machine-read from the scan: it contains errors, and its APL is wrong. Shown for searching; read the PDF.
VECTOR Vol.10 No.2
Hackers Corner: A WindowsTask-Killer for APL by Duncan Pearson
Adrian Smith came to methe other day and said If | start a Windows program from Dyalog with DCMD howcan kill it again from within APL? . So we dived for the manuals and found out a few interesting things. First of all the CMD function, when usedto start a Windowstask, returns a number.
+01CMD 'notepad.exe' minimised! 12345
Aha ! say we, this lookslike a task handle. Why not send a Windows QUIT message to the task and see if it kills itself. If you are a Windowstask then getting a WM_QUIT is like being locked in a room with bottle of whiskey and a loaded revolver and being told to get on withit. It looked like a goodbet.
So we did. We used (WA to associate the PostAppMessage windowsfunction OWA 'I user. P16|PostAppMessage U U I Iu!
and weposted the task a WM_QUIT (message number 18) PostAppMessage 12345 18 0 0
Hello DOS prompt, goodbye Windows bummer! said Pooh!
Apparently OCMD returns something called an hinstance whichis not a task handle but an instance handle, So is there a way from oneto the other? As a matter of fact there is, but you have to look for it. There is a pair of functions in toolhelp.dll with which one can go roundall the tasks in the Windowsevent- queue collecting information from them. One of the bits of information is the hinstance and anotheris the task-handle.
Weassociate them thus: OVA 'I toolheip.Pi6|faskFirst ={Iu4 VUUUIIII 862 8 clic] © uy GWA 'I toolhelp.P16|TaskNext ={I4 UUUUIIIII I U clio} © oy
They are pretty much the same. Each one takes a horrible structure called a TASKENTRY andreturns it (the = means take and return the argument). We pass fPaskFirst an emptystructure andit fills it with details of thefirst task in the
126
VECTOR Vol.10 No.2
queue. Wepassthefilled structure to TaskNext andit replaces the information aboutthe first task with information about the next task. We carry on calling TaskNext until we find a task with the hinstance that was returned, get the task handle of that task from the structure and send it a WM_QUIT.
WhatI omitted to say was what the horrible structure meant. We get back twelve numbers, a ten-character text vector and two more numbers. The text string is the task name, the second number is the task handle and the fourth is the hinstance. I m suretherestis very useful, but not right now soI will ignoreit.
¥ taskfns C1] 8 Associate some useful Windows fns t C2] 'pam'OWA'I user.exe.P16|PostAppMessage UU I Iu C3] first! QNA'I toolhelp.Pi6}faskFirst ={T4 U UY UIIIIIIV efio] © uyt cal tnext'OWA'l toolhelp.Pi6|faskWext ={T4 UU UY I rl ruc Cio] I gv}! v
¥ list+Task_List;qqipam;first;next C12 a List handles and names of all extant tasks {2) taskfns 0 list+'! £3] qg+2arirste (12440), (cide! 1),0 0 Ca] Nextinme13ogqg 0° am+("1+nm DAVC1)) tam cs] dist;+cnm Ce] >('DYALOG'=6tnm) to C71 qq+2anext<qg C8] aNext
¥ Kilj_Name name;qq;pam;first;next [1] a Kill task by name C2] taskfos tal gqgr2zfirstc(12t60},(c10p' 1),0 0 Cay Next:+(namex(pname)}t13ogq)tKill cs) +('DYALOG!=64213 gg) to ced qq+2enextegg C77 aNext Cal Kill:gg+pam(2>gq}18 0 0 ¥
Vv Xill_Num hinstance;qq;pam;first;next (1) a Kill by instance handle (returned by dyalog on UCMD) C2] a W,B. It had better be therelt Ca] taskins Cs] gge2ofirstc(12tu0),(e10p' 17,0 6 Cs] Next:>(hinstance=42qq)tKiil Cel qq+zenextegg C7] wNext Ce] Kill:gq+pam(2>gqg)1iB 0 a y
Kill_Name 'CLOCK* & Harmless enough Kill_Name 'PROGMAN' a Less sensible ... Kili_Name Task_List a... for a very clear desktop!
127