title: C# Modern way to Generate BSOD
body: <p>I am a former field technician for a very large Telecommunications company and part of my job was to install Anti-Virus software for customers during network installations. The problem is many residential systems are already infected or bogged down with startup programs making the simplest task turn in to nightmares. This includes running msconfig and swapping between tabs.</p>
  
  <p>I have written a utility that will automatically run from a USB boot drive to temporarily disable all the programs in startup then automatically reboot the machine but I have 2 issues I need to resolve so technicians can spend time on more important task. One issue is my call to restart the machine makes it impossible to determine if my code is done executing because some systems can take hours to process my automated shutdown code due to limited memory resources. The other issue is with rouge software that has a background worker to detect if they have been disabled in startup and reactivates themselves milliseconds after I disable them.</p>
  
  <p>I have a genuine cause to generate a BSOD to prevent these issues but none of the legacy procedures work on Win10. </p>
  
  <p><code>KeBugCheck</code> generates a:</p>
  
  <blockquote>
    <p>DLLNotFoundError </p>
  </blockquote>
  
  <p>...if I try to import NtosKrnl.exe with an extern call</p>
  
  <p>Source: <a href="https://stackoverflow.com/questions/5737118/programmatically-trigger-bsod">programmatically trigger BSOD</a>
  Windows10 (Access Denied With Elevated Privs)</p>
  
  <pre><code>    System.Diagnostics.Process.GetProcessesByName("csrss")[0].Kill();
  </code></pre>
  
  <p>Windows10 (This works but also triggers shutdown calls for rouge software)</p>
  
  <pre><code>    public static void ShutDown(bool Forced)
      {
              Process[] processess = Process.GetProcesses();//Get all the process in your system
  
              foreach (var process in processess)
              {
                  try
                  {
                      Console.WriteLine(process.ProcessName);
                      process.PriorityClass = ProcessPriorityClass.BelowNormal; //sets all the process to below normal priority
                      process.Kill();
                  }
                  catch (Exception E)
                  {
                      Console.WriteLine(E.Message + " :: [ " + process.ProcessName + " ] Could not be killed");
                  }
  
              }
      }
  </code></pre>
  
  <p>Windows10 (Exiting in middle of Ping has no effect)</p>
  
  <pre><code>    public static void ShutDown(bool Forced)
      {
          Ping Tcp = new Ping();
          Byte[] buffer = new Byte[0];
          Tcp.Send("www.microsoft.com", 12000, buffer);
          Environment.Exit(1);
      }
  </code></pre>
  
  <p>It would be nice to include a Third-Party utility I could extract from a resource file and execute to simulate a crash like NotMyFault but their EULA has some tight restrictions that limit me. I do not want any legal trouble.</p>