TL;DR Occasionally you will get a Virtualbox VM into a locked state and this will prevent it being deleted. Attempts to delete or unregister the VM result in the error Stderr: VBoxManage: error: The machine ’centos64_c6402_1454036461345_59755’ is already locked for a session (or being unlocked). This article describes how to resolve this problem.

The Virtualbox virtual machine (VM) you are trying to remove or unregister is ‘locked’ producing an error like the folowing.

1Stderr: VBoxManage: error: The machine 'centos64_c6402_1454036461345_59755' is already locked for a session (or being unlocked) 
2VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports 
3VBoxManage: error: Context: "LockMachine(a->session, LockType_Write)" at line 493 of file VBoxManageModifyVM.cpp

The simplest way I know the ‘unlock’ this sort of VM is using an ‘emergencystop.

1VBoxManage startvm <vm-uuid> --type emergencystop

Where <vm-uuid> is found using VMoxManage list vms (the UUID being the long collection of characters between the {} at the end of each line).

1VBoxManage list vms
1"Whonix-Gateway" {d89a93c5-d0f3-48ef-9e5c-bf0df89931f1} 
2"Whonix-Workstation" {05647ae6-792c-4caf-be5e-1508c6d012cf} 
3"Buscador-1.2(3-10-18)" {c44145ec-5a71-44b2-a6cb-c590ab92d273}

Once the VM is unlocked you can remove it as usual.

1VBoxManage unregistervm --delete <vm-uuid>

Or simply unregister it if you have deleted the VM files already.

1VBoxManage unregistervm <vm-uuid>