180

I need to test equipment behaviour in the event that Windows hard hangs/freezes (e.g. frozen screen, no LEDs blinking, no reaction to inputs, including Ctrl+Alt+Del, etc.). In order to have enough experiments in a reasonably short time I need to initiate these hangs either programmatically or otherwise.

I am interested in Windows 10 in particular but any working way for other versions is appreciated.

Every search I've done on this topic not surprisingly brings me to discussions on how to eliminate these situations, not provoke them. So the question may seem odd enough.

Feedback: I've tried many of the recipes offered in answers and comments. First of all, I was not interested in crashes that bring BSoD (that's why I described a freeze, not a crash).

I must confess that Windows 10 64-bit showed good resistance to many of the ways. It copes with almost any CPU-load method (including fork-bomb, loops, etc.) quite well. Methods that raise immediate errors (most of NotMyFault hang methods) are handled by the OS with reboot or shutdown (which is not what I pursued). The best results were achieved by memory leak methods of NotMyFault — real freeze with no chance of reboot.

Finally, I was impressed by amount of documentation by Microsoft that talks about making Windows freeze. Looks like they know this part much better than the opposite (fighting freezes) ;-)

hypers
  • 1,562

13 Answers13

228

Maybe this can help: Forcing a System Crash from the Keyboard

With USB keyboards, you must enable the keyboard-initiated crash in the registry. In the registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\kbdhid\Parameters, create a value named CrashOnCtrlScroll, and set it equal to a REG_DWORD value of 0x01.

You must restart the system for these settings to take effect.

After this is completed, the keyboard crash can be initiated by using the following hotkey sequence: Hold down the rightmost CTRL key, and press the SCROLL LOCK key twice.

Or you could start a fork bomb: see this SO question

There is also NotMyFault

Notmyfault is a tool that you can use to crash, hang, and cause kernel memory leaks on your Windows system. It’s useful for learning how to identify and diagnose device driver and hardware problems, and you can also use it to generate blue screen dump files on misbehaving systems.

duenni
  • 2,299
  • 2
  • 17
  • 22
24

It sounds like you're testing the reaction of an external device to an OS becoming unresponsive.

If your hardware can be connected to a virtualized Windows install, then you can pause and resume the virtual machine as many times as you like. Install the desired OS in a VirtualBox (or other desktop virtualization) environment, expose whatever hardware interface is being used (USB, Ethernet, or whatever) to the VM.

You can then pause and resume the virtual machine at will.

barbecue
  • 1,278
22

At least under an older Windows version (some years ago) the following worked:

I wrote a C program with an endless loop:

while(1) {}

... then I gave that program "realtime priority" in the task manager (there is also an API which can do this).

On a multi-core system I would need to do this multiple times so one loop is running on each core...

10

The strongest kernel hang (i.e., no mouse tracking, etc.) is when code goes into an infinite loop in kernel mode with interrupts off.

It's possible to achieve this with a device driver, and even better, you can write the driver so that it starts and stops the hang under your control (assuming the infinite loop is testing the condition you're in control of).

How to write and install this driver would be the topic of another question or three, but that's the approach I'd take.

8

Please check the following question on StackOverflow which is similar to yours: How to make windows freeze for short period of time

The tl;dr of it is that there's no way to (reliably) do it.

Rather than freezing or getting Windows to hang, maybe you can just interrupt the communication with your equipment.

I have no idea what your equipment is and how you connect it. If it's USB or Ethernet adapter, e.g, you could easily deactivate it in the Device Manager or unplug? If you forcefully crash or hang the system you might damage your system in various ways, so be careful with what you do.

Seth
  • 9,393
Ralf
  • 272
5

Is kernel debug mode not an option?

I've set it up in Windows 7, and the linked instructions in this answer specify XP or later, so it should work with Windows 10.

I've set it up over FireWire/1394, since it's the easiest, in my opinion. But you can also do it over the network or USB (and more).

Basically,

Setup the target computer by running these commands in an elevated prompt (picking a channel n):

bcdedit /debug on
bcdedit /dbgsettings 1394 channel:n

Which is the same as going to the boot tab of msconfig, and selecting the 'Advanced' button:

enter image description here

enter image description here

Then (after rebooting the target computer), run WinDbg on the host computer using the same bitness of WinDbg of the target computer.

Then it's just a matter of pausing kernel execution whenever you want from the host computer. If you test equipment has some asynchronous operation that it is running this should be as effective as other means.

Nick
  • 688
3

This bug (Wayback machine link) freezes Windows pretty quickly due to resource exhausting. Easy to reproduce too.

As it turns out, this is actually a bug (Wayback machine link) in how the command line (more specifically cmd.exe) parses batch files and could lead to a quick denial of service type attack; putting the following line in a batch file (with no new lines) will consume massive amounts of memory very quickly due to this bug (as an example):

^ nul<^

Long story short, when a caret is at the end of the file, the actual end of file is 'ignored' and the file handle 'reset' to 0 (essentially) so that the batch is parsed again (ad infinitum).

beatcracker
  • 2,712
2

I don't know if this qualifies as a total freeze because the mouse cursor still moves on the screen, but Windows 7 UI becomes unresponsive if you have device I/O errors more specifically a hard drive failure. One of my hard drives was self-reporting imminent drive failure via SMART and Windows 7 would mount it but hang whenever I tried to access certain files saved on it. The UI would lock up (except for the mouse cursor movement) for up to 5 minutes until it either could read the file or dismounted the drive after the time-out. I don't know if Windows uses the system clock for the timeout, but maybe if you somehow freeze the time you can extend the timeout length? Maybe this will get you part way there, but not 100% the answer you're looking for.

Dotes
  • 121
2

Here's the source code of an application that I use in my debugging lessons. It shows how a user mode application can perform a sort of DoS attack.

You'll notice that your mouse cursor moves very seldom (once every eleven seconds on my machine). Potentially your PC will still react on the Power button if you wait long enough.

It works using an endless loop and setting the highest priority to the process (0x100 "realtime") and setting the highest priority to the threads (15 "time critical"). It will start 8 of them, which is enough for i7 computers. If you need more, adapt the loop. More of them will potentially slow down things more.

#include "stdafx.h"
#include <windows.h>
#include <string>
#include <sstream>
#include <iostream>

void WasteTime()
{
    int priority = 15;
    ::SetThreadPriority(::GetCurrentThread(), priority);
    while (true)
    {
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    ::SetPriorityClass(::GetCurrentProcess(), 0x100);
    for(int i=0; i<7; i++)
    {
        LPDWORD threadid = 0;
        ::CreateThread(NULL, 64*1024, (LPTHREAD_START_ROUTINE)&WasteTime, NULL, 0, threadid);
        ::Sleep(2000);
    }

    WasteTime();

    return 0;
}
0

Did you try the CPUEater utility that is bundled with Process Lasso ? Ps. I do not work for bitsum.

beppe9000
  • 731
-2

If you really want to hang your PC, totally causing it to just freeze, simply use up all of its RAM and force it to page memory. That will go beyond mere freezing and really just overload the thing such that you can't even use Task Manager, not even by keyboard. Even when the process is terminated, it will take a long time for the PC to recover. (It's the best!)

You could for instance create a class with a pointer to itself, and in a while loop, create a new instance of that class forever, storing each new instance in the previous instance's pointer. Maybe add some doubles or vectors to the class too, to consume memory more quickly. Then you could have a timer that exits the while loop and deconstructs everything; of course, you'll have to wait a bit for it to recover.

Andrew
  • 632
-4

I would suggest simply creating a batch file with the following code:

@echo off
:x
start cmd.exe
start explorer.exe
start calc.exe
start notepad.exe
start iexplorer.exe
start paint.exe
goto x

This is probably the easiest and safest way to do it. You can replace the process names with any windows applications.

SLimy
  • 9
-9
  1. Go to C:\Windows\Temp\
  2. Hit Ctrl-a for Select All
  3. Hit Enter