home *** CD-ROM | disk | FTP | other *** search
- /*
- TASKWALK.C -- Generates a list of Windows tasks
-
- From Chapter 5 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC TASKWALK (for Borland C++ v3.00)
- WINIOMS TASKWALK (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include <dos.h>
- #include "winio.h"
-
- #ifndef __BORLANDC__
- #define MK_FP(a,b) ((void far *)(((unsigned long)(a) << 16) | (b)))
- #endif
-
- /* GetCurrentTask is documented, but only with WORD retval */
- DWORD (FAR PASCAL *GetCurrentTaskD)(void);
-
- main()
- {
- HWND hwnd = winio_current();
- DWORD dwTask;
- WORD wFirstTask, wNextTask;
- WORD wNumTasks;
-
- winio_about("TASKWALK"
- "\nGenerates a list of Windows tasks"
- "\n\nFrom Chapter 5 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- GetCurrentTaskD = GetCurrentTask;
-
- dwTask = GetCurrentTaskD();
- wFirstTask = HIWORD(dwTask); // get base of linked list
- wNextTask = wFirstTask;
- wNumTasks = 0;
- printf("%lx\n", dwTask);
- winio_setpaint(hwnd,FALSE); // so we don't yield while walking task list!
- for (;;)
- {
- /*
- See the description of the Task Database data structure
- for an explanation of offsets 0 and 0F2h.
- */
- char far *fp;
- char modname[9], *p=modname;
- int i;
- /* Copy the modname name at offset 0F2h in the Task Database */
- for (i=0, fp= (char far *) MK_FP(wNextTask,0xf2); i<8; i++, p++, fp++)
- *p = *fp;
- *p = '\0';
- printf("%04x %s", wNextTask, modname);
- if (wNextTask == GetCurrentTask())
- printf(" <== current task");
- printf("\n");
- wNumTasks++;
- /* Get the handle of the next task from offset 0 in the Task DB */
- wNextTask = *((WORD far *) MK_FP(wNextTask, 0));
- if (wNextTask == 0)
- break;
- }
- if (wNumTasks != GetNumTasks())
- fail("Wrong number of tasks!");
- winio_setpaint(hwnd,TRUE);
- return 0;
- }
-
-