Click here to Skip to main content
13,353,106 members (65,692 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 27 Mar 2003

The Ultimate Process/Thread spy for Windows 9x.

, 27 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Process/thread creation/destruction detector for Windows 9x .


This article teaches you the way to detect Process/Thread creation/destruction on Win9x platforms.

Background Of Project

On Windows, processes and threads are the main area of interest for a system programmer. Many of you might have seen many tools & code for dealing with processes and threads on Windows NT/2000 based systems. Here I am introducing a process/thread creation/destruction detector for Windows 95/98 , really...:)

Description of Technique

Till now, you might have found ways to detect process creation on NT platforms using Kernel mode component which uses PsSetCreateProcessNotifyRoutine. But like me, you might not have found a way to detect process/threads on Win9X platforms. I found many places on the Web, describing about process creation on Win9X using CREATE_PROCESS message of VMM, but never found it easy to add handler to CREATE_PROCESS in VXD. Because it's undocumented in 98 DDK. MS 98DDK headers/documentation have description about CREATE_THREAD message, but not for CREATE_PROCESS. You will find the definition of CREATE_PROCESS, but wont find how to get the PID of a newly created process. For thread (CREATE_THREAD), the thread ID is passed in EDI register, but for CREATE_PROCESS it's not there. At last, by trial and error I found where it is, the PID value, it is in EDX reg.

Well, let's start talking about the project. There are 2 components in this project: 1st is Win32 RING 3 executable, which creates handle to VXD and passes function address to get called when process/thread creates/destroys. Second is VXD (Not WDM) which uses CREATE_PROCESS, CREATE_THREAD, DESTROY_THREAD, DESTROY_PROCESS VMM messages to detect the process/thread execution/death. VXD uses APC mechanism to call user mode program's function.

Background about VXD component: On Win9x/ME platforms (Consumer Windows), VXDs are the kernel mode components. Simply saying, VXD is ring 0 component on Win9x. VXDs are different from NT drivers in many ways. Like VXDs are not PE binaries, they have VMM's message processing kind of architecture which is very similar to Win32 message processing. VMM (Win98 kernel) sends many messages to VXD. Dispatch Handler defined in VXD gets called for these messages. The parameters like PID/TID are passed in CPU registers. The VXD presented here processes CREATE_PROCESS, DESTROY_PROCESS, CREATE_THREAD, DESTROY_THREAD messages, and calls ring 3 function (from kernel mode to user mode, great !) using APC. Following is the messages map of VXD, to map functions to messages. You can understand it by looking at it, similar to MFC message maps.


Well, following is the DeviceIOControl handler in VXD. This function is called in VXD whenever DeviceIoControl, CreateFile and CloseFile are called in user mode on VXD's handle.

// VXD DevIoControl handler.

DWORD OnW32DeviceIoControl(ULONG dwService/*IOCTL*/, DWORD dwDDB,
    DWORD hDevice, struct DIOCParams* lpDIOCParms
    /*Param's passed from DeviceIoControl*/)
    DWORD dwRet = 0;

    switch (dwService)
    case DIOC_OPEN: // CreateFile call
        _Debug_Printf_Service("Created Handle to Chikago driver!\n");

        _Debug_Printf_Service("Closed Handle to Chikago driver!\n");
        // CloseHandle call
        dwRet =    0; //
        Return    success 
    case IOCTL_TEST: 
          // _Debug_Printf_Service("Chikago Obtained APC func address.!\n");
              *((PDWORD)(lpDIOCParms->lpcbBytesReturned)) = 0;
           FunctionEventAPC=*((PVOID*)lpDIOCParms->lpvInBuffer ); 
           //Take Function address.
           // Store the Thread handle for APC queueing.
           //The APC will be qued in this thread. 
           //TheThreadT is global VOID * variable
        dwRet = 0;

    case     IOCTL_RELEASE:
             _Debug_Printf_Service("Release Memory Called%d\n",0);
            _HeapFree(*(PVOID*)lpDIOCParms->lpvInBuffer,0); // Release memory
        dwRet = 1;

    return dwRet;

Above shown function is the ENGINE part of VXD, it processes IOCTL passed from user mode application. Here you can see 2 major IOCTL codes: IOCTL_TEST and IOCTL_RELEASE. IOCTL_TEST is used to pass the address of callback function using DeviceIoControl. See following code of ring 3 EXE which calls DeviceIOControl to pass the function address. (The function names APCFunc will get called on process/thread creation/death.)

// Win32 App...calling VXD.
int main()
    BOOL bRet;
    DWORD cbRet;
    char buf[80];
    PVOID inbuf;

    // Adjustment because VXD is in BIN folder
         // Open handle to VxD
         hDevice = CreateFile("\\\\.\\CHIKAGO.VXD",

    if (hDevice == INVALID_HANDLE_VALUE)
        printf("Failed to open handle to CHIKAGO.VXD\n");
        // Send the VxD Function address , this function will be called.
        bRet = DeviceIoControl(hDevice,

        if (bRet)
            printf("Press CTRL+C to terminate");
            printf("IOCTL_TEST failed\n");

            SleepEx(-1,TRUE); //Keep waiting otherwise APC wont work.        
        CloseHandle(hDevice); //Done
    return 0;

When VXD gets call for on IOCTL_TEST, it saves the input buffer in global variable named PVOID FunctionEventAPC. The calling thread ID is also stored in TheThreadT named DWORD variable since it's necessary to use APC. Now following is CREATE_PROCESS handler routine (other handlers are same as this.):

void OnProcessCreate(DWORD pid)
    APCDataX * apm;
    apm->dwCreated =TRUE; //Creation
    apm->dwIdDATA =pid;
    apm->dwThreadOrProcess =TRUE; // Process
    _Debug_Printf_Service("%d Process Created\n",pid);

void OnCreateThread(DWORD tid)
    APCDataX * apm;
    apm->dwCreated =TRUE; // It's Created
    apm->dwIdDATA =tid;
    apm->dwThreadOrProcess =FALSE;// False means it's Thread
    _Debug_Printf_Service("%d Thread Created\n",tid);


void OnDestroyProcess(DWORD pid)
    APCDataX * apm;
    apm->dwCreated =FALSE;// FALSE means it's Destroyed
    apm->dwIdDATA =pid;
    apm->dwThreadOrProcess =TRUE;//It's a Process
    _Debug_Printf_Service("%d Process Destroyed\n",pid);

void OnDestroyThread(DWORD tid)

    APCDataX * apm;
    apm->dwCreated =FALSE; // FALSE means it's Destroyed
    apm->dwIdDATA =tid;
    apm->dwThreadOrProcess =FALSE; // False means it's Thread
    _Debug_Printf_Service("%d Thread Destroyed\n",tid); 


This handler queues an APC to the thread (which is main function of ring 3 exe in our case.). The VXD passes a structure pointer filled with PID and flags to differentiate between process and thread to user mode function (APCFunc). Here is APCFunc:

void APCFunc(struct APCDataXX * data)
            printf("Process Created %u\n",data->dwIdDATA);
            printf("Process Destroyed %u\n",data->dwIdDATA);
        if(data->dwCreated ==TRUE)
            printf("Thread Created %u\n",data->dwIdDATA);
            printf("Thread Destroyed %u\n",data->dwIdDATA);

    DeviceIoControl(hDevice, IOCTL_RELEASE, &data, sizeof(PVOID),0,0,0,0);
    //Call this to release the memory allocated in VXD.

Quite simple! It identifies whether process or thread was created/died. And then sends IOCTL_RELESE to free the memory allocated by VXD. VXD frees the memory using _HeapFree service/function of VMM.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ramkrishna Pawar
Web Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralDetect and block process start Pin
Juliano27-Feb-06 1:30
memberJuliano27-Feb-06 1:30 
GeneralRe: Detect and block process start Pin
Ramkrishna Pawar27-Feb-06 1:36
memberRamkrishna Pawar27-Feb-06 1:36 
GeneralRe: Detect and block process start Pin
Juliano27-Feb-06 4:27
memberJuliano27-Feb-06 4:27 
GeneralCan't see _Debug_Printf_Service output Pin
Eternia17-Jun-05 2:12
memberEternia17-Jun-05 2:12 
GeneralRe: Can't see _Debug_Printf_Service output Pin
Eternia128-Jun-05 5:03
memberEternia128-Jun-05 5:03 
GeneralMore info from Process Pin
zandar the great2-Nov-04 10:37
memberzandar the great2-Nov-04 10:37 
GeneralRe: More info from Process Pin
Ramkrishna Pawar2-Nov-04 20:04
memberRamkrishna Pawar2-Nov-04 20:04 
GeneralStopping window delete operation Pin
Anonymous14-Aug-04 2:23
sussAnonymous14-Aug-04 2:23 
GeneralRe: Stopping window delete operation Pin
Ramkrishna Pawar14-Aug-04 4:13
memberRamkrishna Pawar14-Aug-04 4:13 
QuestionHow to Hook in registry Pin
mailMonty</9-Feb-04 19:27
membermailMonty9-Feb-04 19:27 
AnswerRe: How to Hook in registry Pin
Ramkrishna Pawar9-Feb-04 19:34
memberRamkrishna Pawar9-Feb-04 19:34 
GeneralRe: How to Hook in registry Pin
mailMonty</9-Feb-04 19:57
membermailMonty9-Feb-04 19:57 
GeneralRe: How to Hook in registry Pin
Ramkrishna Pawar9-Mar-04 21:51
memberRamkrishna Pawar9-Mar-04 21:51 
Questioninto a DLL? Pin
alkolik23-Dec-03 1:50
memberalkolik23-Dec-03 1:50 
AnswerRe: into a DLL? Pin
Ramkrishna Pawar23-Dec-03 2:23
memberRamkrishna Pawar23-Dec-03 2:23 
GeneralRe: into a DLL? Pin
alkolik23-Dec-03 3:33
memberalkolik23-Dec-03 3:33 
GeneralRe: into a DLL? Pin
Ramkrishna Pawar23-Dec-03 19:23
memberRamkrishna Pawar23-Dec-03 19:23 
GeneralWINDOWS 2000 version Pin
NeelWin321-Sep-03 2:51
memberNeelWin321-Sep-03 2:51 
GeneralRe: WINDOWS 2000 version Pin
Ramkrishna Pawar10-Dec-03 3:48
sussRamkrishna Pawar10-Dec-03 3:48 
GeneralTry TaskInfo2003 Pin
Marc Clifton28-Mar-03 2:10
memberMarc Clifton28-Mar-03 2:10 
GeneralRe: Try TaskInfo2003 Pin
Ramkrishna Pawar28-Mar-03 2:16
memberRamkrishna Pawar28-Mar-03 2:16 
GeneralRe: Try TaskInfo2003 Pin
Norm Almond28-Mar-03 3:37
memberNorm Almond28-Mar-03 3:37 
GeneralRe: Try TaskInfo2003 Pin
Marc Clifton28-Mar-03 4:32
memberMarc Clifton28-Mar-03 4:32 
GeneralRe: Try TaskInfo2003 Pin
Ramkrishna Pawar30-Mar-03 18:59
memberRamkrishna Pawar30-Mar-03 18:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 28 Mar 2003
Article Copyright 2003 by Ramkrishna Pawar
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid