Run your VM as a Windows Service
This is an optional section - You only need to complete this section if you would like the VM to startup (headless) automatically when your windows machines starts.
Instructions:
- On your host machine, open the following url - https://github.com/onlyfang/VBoxVmService/releases/ and download the latest version of the tool.
- Run the executable.
- When prompted, accept the license, and click Next.
- Select the directory you would like the tool installed, and click Next.
- Accept the default Start Menu Folder, and click Next.
- Complete the installation by clicking Install followed by Finish.
- Open the VBoxVmService.ini file - it is located in the tools installation directory.
- For now remove the [VM1] section.
- Change the VmName in the [VM0] section, to be that of your VM. This name can be seen in VirtualBox, but in this example it should be ‘AnsibleControlNode’.
- Change the ShutdownMethod in the [VM0] section to be ‘acpipowerbutton’.
- Under the [Settings] section, add the following two lines. They can be removed once the service is installed. Save the file when finished.
RunAsUser=.\USERNAME UserPassword=PASSWORD
- Open a command prompt (as administrator) in the installation directory. Run ‘VmServiceControl.exe -i’.
- You may get an error saying the service already exists. If so run these commands;
VmServiceControl.exe -u VmServiceControl.exe -i
- It is now a decent idea to restart your windows laptop. It will take a few minutes after the laptop boots until your VM boots in the background. Test this by connecting directly via Putty, rather than opening VirtualBox.