Windows 10 on Mac with Boot Camp: making Intel HAXM work without crashing the system

Andrea Bresolin
5 min readNov 16, 2017

I’m writing this post because I’ve seen many people struggling to find a solution and I couldn’t find a proper one anywhere, so I hope this is going to help you solve this issue. The post refers to the Android emulator, but actually it might apply to any virtual machine taking advantage of the hardware acceleration provided by Intel HAXM (Intel Hardware Accelerated Execution Manager). This issue appears for me on Windows 10 Pro Fall Creators Update on a mid-2014 MacBook Pro with Intel HAXM 6.2.1, but from the forums on the web it looks like people had this issue for years even with previous versions of Windows, usually when running on a Mac.

You’ve just installed Windows on your Mac with the help of Boot Camp. You’ve finally set up everything, then you install Intel HAXM and start your Android emulator. All good. It works without any issue. Then you close the emulator, you put your laptop to sleep. You open it up again, you launch the emulator and… boom! The nice blue screen appears to inform you that the whole Windows crashed! What’s going on? Why is this happening? Let’s take a look at the issue.

After doing some research, it looks like this issue is quite specific to Intel HAXM running on Windows installed on a Mac (in my case a MacBook Pro). It doesn’t actually happen on a proper PC with Windows. It seems like the power management layer in Windows together with the MacBook hardware don’t play nicely together.

Here are the different cases that you could have while working with the Android emulator (and possibly other virtual machines):

  1. You put Windows into sleep mode while the emulator is running, you wake up Windows, the emulator is still running, you close the emulator, you restart it, all good, no problems at all.
  2. You’ve never used the emulator in your current Windows session, you’ve put Windows into sleep mode and woken it up multiple times, you run the emulator, again all fine, it runs without any issue.
  3. You’ve used the emulator at least once in your current Windows session, then you put Windows into sleep mode while the emulator is NOT running, you wake up Windows, you start the emulator and Windows immediately crashes with the blue screen.

As you can see, we just need to solve the third case because that’s the only one causing the issue.

The solution that I’ve found consists in restarting the Intel HAXM service to restore its state as it is before running any virtual machine after starting a fresh Windows session.

Let’s take a look at the steps.

Create a BAT script to restart the Intel HAXM service

Create a BAT file (let’s call it restartHAXM.bat) with the following content:

@echo off
tasklist | findstr "qemu" >nul || net stop "IntelHaxm" >nul && net start "IntelHaxm" >nul

Note: the command starting with tasklisk is actually all in one line until the last nul even though here you might see it on multiple lines because of the width constraints in the post.

This command performs the following steps:

  1. tasklist gets the list of all the running processes in Windows
  2. findstr searches for a process that contains the string qemu to check if the Android emulator is running (if you need to search for the process of another virtual machine, then just replace the string qemu with the one you need)
  3. only if the process is NOT found (so it’s not running and not keeping the Intel HAXM service busy), then net stop ends the service named IntelHAXM
  4. when the service is stopped, then net start restarts the service

The reason why we need to use net instead of sc to stop and start the service is that net is synchronous while sc is asynchronous. This means that net actually waits for the service to stop or start before returning while sc returns immediately. This is particularly important for our case because we are trying to restart the service so we need to wait for it to stop before trying to start it again. Luckily stopping or starting the Intel HAXM service is basically instant so there’s no wait at all.

The previous script makes sure that we restart the Intel HAXM service only when it can be restarted, so only when there are no virtual machines running.

Create a scheduled task in Windows to restart Intel HAXM automatically when Windows wakes up after sleeping

Now we need to automatically restart the Intel HAXM service whenever Windows wakes up after sleeping. To do this transparently, we can create a new scheduled task.

First of all, we have to find out what event we have in Windows to check if the system woke up after entering the sleep mode. For this you can use the Event Viewer. The right event can be found in Windows Logs -> System.

Windows Event: “The system has returned from a low power state.”

So you need the event with ID 1 and source Power-Troubleshooter.

Now you need to start the Task Scheduler to create a new task. From there, select Create Task… and make sure you fill the fields in the following way:

NOTE: make sure you use a user account with administration privileges
Create a new trigger
Set the Windows event
Create a new action to run the BAT file that restarts the service
Select your BAT file and set the action as Start a program
Set the conditions
Set the settings

That’s it. You can now enjoy using Intel HAXM without worrying anymore that Windows is going to crash on your Mac. Every time Windows wakes up after the sleep mode, the Intel HAXM service will be restarted automatically whenever it’s needed.

--

--