Ubuntu: How can I use a script to control a VirtualBox guest?



Question:

Refer to : Launch an application in Windows from the Ubuntu desktop

I was wondering if Takkat could elaborate on the actual execution i.e. howto in the script file.

This will be greatly helpful. Thanks in advance

my script file InternetExplorerVM.sh looks like this, execution is

/path/to/InternetExplorerVM.sh "C:\Program Files\Internet Explorer\iexplore.exe"    #!/bin/bash    # start Internet Explorer inside of a Windows7 Ultimate VM  echo "Starting 'Internet Explorer' browser inside Windows7 virtual machine"  echo ""  sleep 1  echo "Please be patient"    VBoxManage startvm b307622e-6b5e-4e47-a427-84760cf2312b    sleep 15    echo ""  echo "Now starting 'Internet Explorer'"  ##VBoxManage --nologo guestcontrol b307622e-6b5e-4e47-a427-84760cf2312b execute --image "$1" --username RailroadGuest --password bnsf1234    VBoxManage --nologo guestcontrol b307622e-6b5e-4e47-a427-84760cf2312b execute --image "C:\\Program/ Files\\Internet/ Explorer\\iexplore.exe" --username RailroadGuest --password bnsf1234 --wait-exit --wait-stdout    echo ""  echo "Saving the VM's state now"  VBoxManage controlvm b307622e-6b5e-4e47-a427-84760cf2312b savestate    sleep 2    #Check VM state  echo ""  echo "Check the VM state"  VBoxManage showvminfo b307622e-6b5e-4e47-a427-84760cf2312b | grep State    exit  

My apologies for any mistakes, this is my first time posting on askubuntu.Thanks a ton in advance. This has been very helpful. Need this for BNSF guests, their Mainframe emulator works exclusively on Java enabled Internet Explorer.


Solution:1

He's basically saying you can do this:

  1. Create a Virtual Machine, like a Windows virtual machine.
  2. Login to the virtual machine.
  3. Switch the virtual machine into "seamless" mode
  4. Save the state of the virtual machine in the main Virtual Box window.
  5. Create a bash script with the VBoxManage commands, so that you can do something like ./runinwindows "C:\\some\\path\\executable.exe"

For example:

#!/bin/bash  # Start the VM  VBoxManage startvm "<Name_of_VM>"    # Run the executable  VBoxManage --nologo guestcontrol "<Name_of_VM>" execute --image "$1" --username windowsuser --password password --wait-exit --wait-stdout    # Save the current machine state for the next time you run the script.  VBoxManage controlvm "Name_of_VM" savestate  

Then you could run a Windows executable (in this case) in your terminal, but it would actually be running in a virtual machine.


Solution:2

I wrote a script to control a virtual machine using VBoxManage. you can execute commandS using the script like this:

./vmcontrol.sh -m [VMName] [Your Command]  

The script:

#!/bin/bash  #Creation du script vmcontrol.sh    function execute  {          vmname=\$1;      command=\$2;      shift 2;      VBoxManage --nologo guestcontrol \$vmname execute --image \$command --username root --password root --wait-exit --wait-stdout --wait-stderr -- \$@ 2>&1  ;        }    param=\$1;  #Execution d'une commande  if [ \$param = "-e" ]  then      command=\$2;      shift 1;      execute "Xubuntu" \$@ ;  #Execution d'une commande dans une vm donnée  elif [ \$param = "-m" ]      then           vmname=\$2;          command=\$3;          shift 1;          execute \$@  #Allumer une machine virtuelle donnée  elif [ \$param = "-s" ]      then          vmname=\$2;          VBoxHeadless --startvm \$vmname;  elif [ \$param = "-c" ]      then          vmname=\$2;          VBoxManage clonevm Xubuntu --mode machine --name \$vmname --basefolder /home/VMs --register ;  elif [ \$param = "-r" ]      then          vmname=\$2;          VBoxManage unregistervm \$vmname  --delete ;  elif [ \$param = "-vbox" ]      then          startx virtualbox;  elif [ \$param = "-i" ]       then      vmname=\$2;          if [ \$vmname = "vms" ]              then              VBoxManage list vms          elif [ \$vmname = "runningvms" ]              then              VBoxManage list runningvms          else               #Erreur               echo "error in commmande";          fi  elif [ \$param = "-sv" ]      then          vmname=\$2;          VBoxManage startvm \$vmname ;  elif [ \$param = "-p" ]      then      vmname=\$2;      VBoxManage controlvm \$vmname  acpipowerbutton;      else           #Erreur           echo "error in commmande";  fi  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »