Freeze Programs Using Win32 Threads

Freezing programs is a lot of fun especially if you can reprogram it to freeze most of the programs on your friends PC using OpenThread and SuspendThread and then with the press of a key you can unfreeze them using ResumeThread and freak out your friends. Using Win32 Threads you can easily freeze any program, in this example we will freeze notepad.exe.

Firstly, Win32 API requires you to define:

#define _WIN32_WINNT 0x0500

Before you are allowed to use OpenThread, to ensure that you are using Windows 2000 and above. If you are using Windows 98, this program will not work with OpenThread.

Using CreateToolhelp32Snapshot we can get a snapshot of all the running processes or running threads. We use that to make sure we are suspending the thread of the right process.

I loop through the threads and processes and compare with our parameters to make sure we have reached the correct process and thread. If you remove some of the if statements you can freeze all the threads or processes in windows, but I would be careful with this trick, it will freeze your whole computer. Of course after 7 seconds everything will become unfrozen.

#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <Tlhelp32.h>


void PauseProcess(DWORD dwPid ,BOOL bResume){
    HANDLE  hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);

    THREADENTRY32 Te32;
    Te32.dwSize = sizeof(THREADENTRY32);

    Thread32First(hSnapShot, &Te32);

    do {
      if(Te32.th32OwnerProcessID == dwPid) {
           HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, Te32.th32ThreadID);
           if(bResume) {
              ResumeThread(hThread);
           } else {
              SuspendThread(hThread);
           }
           CloseHandle(hThread);
       }
    } while(Thread32Next(hSnapShot, &Te32));
    CloseHandle (hSnapShot);
}

void FreezeExe(LPSTR lpExePath, BOOL bResume){
   HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
   PROCESSENTRY32 Pe32;
   Pe32.dwSize = sizeof(PROCESSENTRY32);
   Process32First(hSnapShot, &Pe32);
   do {
     if(strcmp(Pe32.szExeFile, lpExePath ) == 0) {
        PauseProcess(Pe32.th32ProcessID,bResume);
     }
    } while (Process32Next(hSnapShot, &Pe32));
    CloseHandle (hSnapShot);
}

int main(){
    FreezeExe("notepad.exe", false);
    Sleep(7000);
    FreezeExe("notepad.exe", true);
    return 0;
}

After I get a handle to the snapshot of processes that are running, I create a PROCESSENTRY32 structure which will contain process information for each process. Process32First will grab the first process from the snapshot and place it in Pe32 struct.

The loop will test the exe name that is inserted as a parameter and compare it with the current process in the list. Then loop to the next process using Process32Next. Once the loop is done we close the handle.

The same process occurs in PauseProcess but this time with threads.

bResume is used to freeze or unfreeze applications. You don't have to just freeze them using SuspendThread, you can also TerminateThread to shut down an application that you cannot shut down any other way such as a virus.

You can also find out if an application is running or not.

Remember not to be mean, creating programs to constantly freeze other peoples' applications is annoying and you really wouldn't want such a program on your computer, so don't do put it on other people's computer just to annoy them. Make it fun and fixable.

You can look up what each function does by searching the MSDN library for the functions.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.