Remotely boot Windows into OS X
By Morgan Rowe | 11 Feb 2014
If you have a large amount of dual booted Macs, you may find that most, if not, all of them have been booted into Windows when you'd like to do some work on OS X. Personally, I'm able to accomplish most of my tasks using Apple Remote Desktop, so the most time consuming aspect of trying to deploy changes to the Macs is turning them on. If you turn them on and they boot into Windows, it's a bit of a pain to boot them back into OS X. You can login to Windows and use the Boot Camp utility in the system tray to change the startup disk, or hold down the option key at startup to select the OS X partition from the list.
As I'm lazy, I wanted a way to do this from my MacBook (currently running OS X 10.9.1) as I don't fancy individually booting each Mac into OS X using the methods mentioned above. So, is there a way to boot multiple Macs from Windows into OS X remotely using nothing but another Mac? The answer is yes, Winexe!
Homebrew and Winexe
We'll be using Homebrew, which is a package manager for OS X, to install Winexe. You could install Winexe manually, but installing and using Homebrew was a pleasure, so I'm going to encourage you to do the same. You'll want to install this software on the Mac you do your work on rather than one of your client machines.
There're very clear instructions on how to install Homebrew on their website. Open Terminal and run the following command. I advise you go to Homebrew's website to check they haven't changed their installation instructions, but here's how I did it:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Allow it to download and install. When it runs, you’ll be asked to verify that the changes it’ll make to your file system are OK, and to provide your administrator password. You may be asked to install some Xcode command line developer tools, let Software Update find and install the software for you by clicking on “Install”.
Don’t forget to go back to the Terminal window once Software Update has finished to complete the installation.
That's it, Homebrew is installed!
Once it's installed, it asks you to run the following command:
If you’ve installed some libraries in the past, you may get some warning messages. These warnings don’t prevent you from using the Homebrew as it’s just letting you know that it didn’t expect to find them.
I'm not going to into great detail about Homebrew, but if you want to look more into it, type the following command into Terminal:
Now that Homebrew is installed, we can install Winexe with ease. Type the following commands into Terminal followed by return:
brew doctor brew update brew install winexe
It took about four to five minutes to install Winexe on my MacBook and just under four minutes on my iMac.
You may get an error message that prevents you from installing Winexe. If so, read the next step, if not, feel free to skip it.
Can’t locate getopts.pl
Hopefully Winexe installed perfectly, but for me it didn't. I had an error message telling me that a Perl file named “getopts.pl” was missing.
I downloaded "getopts.pl" from the Internet and saved it into
/Library/Perl/5.16/. I ran the following commands again, and it worked.
brew doctor brew update brew install winexe
Winexe should now be installed. It is located in
/usr/local/bin/. If you wish to read up on Winexe before we move on, you can access the help file by typing
If you wish to use Winexe, we must structure the command as follows:
/usr/local/bin/winexe -U DOMAIN/USERNAME%PASSWORD //COMP-NAME 'command here'
You need to pass your domain's name, an administrator account name and password, the computer name, and the command we want to execute on that machine. Note that the username and password are separated with a percentage symbol (%), the computer name must be prepended with a double forward slash, and the command being passed to the remote machine is to be surrounded in single quotes.
For example, if we wanted to restart a remote PC named "eng-01", we'd do it like this:
/usr/local/bin/winexe -U ehcho.com/administrator%123456 //eng-01 'shutdown /r /t 0'
We get a lot of feedback from Winexe, which is nice for trouble shooting. Some errors appear, but despite them, the commands I pass execute as expected.
Change Window's startup disk on a remote Mac
Assuming that Winexe is installed and you're connected to the same network as the remote Mac you're trying to change the startup disk of, execute the following commands:
/usr/local/bin/winexe -U DOMAIN/USERNAME%PASSWORD //COMP-NAME '"c:\Program Files\Boot Camp\Bootcamp.exe" -StartupDisk’
/usr/local/bin/winexe -U DOMAIN/USERNAME%PASSWORD //COMP-NAME 'shutdown /r /t 0'
The first command changes the startup disk to the first OS X partition it finds, and the second restarts the machine. Once is restarts, it should boot into OS X! You can then use Remote Desktop to boot the machines back into Windows if you wish.
Change Window's startup disk on multiple remote Macs
We can use a loop to cycle through a text file containing the names of the Macs we need to execute the above commands on.
First of all, prepare a text file containing the names of your Macs. Make sure the computer names are separated by line returns only.
I used TextEdit in plain text mode to make this. Save the file to your Desktop and call it "comps.txt".
Now run these commands instead:
for computername in $(cat /Users/USERNAME/Desktop/comps.txt);do /usr/local/bin/winexe -U DOMAIN/USERNAME%PASS //$computername '"c:\Program Files\Boot Camp\Bootcamp.exe" -StartupDisk’;done
for computername in $(cat /Users/USERNAME/Desktop/comps.txt);do /usr/local/bin/winexe -U DOMAIN/USERNAME%PASS //$computername 'shutdown /r /t 0';done
It loops through the text file, inserting the computer name into the winexe command. This allows you to reboot all of your Boot Camped Macs from Windows into OS X with ease.
That’s it. Although this post focuses on booting Macs from Windows into OS X using the command line, you can pass any sort of valid command to any Windows PC using this technique - it doesn’t have to just be a Mac.
If you feel more comfortable using Windows to do this sort of task, you can use PsTools, which does everything Winexe does and more!