How to run gui application on windows vm? - vagrant

I have installed vagrant and virtual box on my Mac. I have created a Windows10 VM and it's configured with winrm.
I am able to run commands on Windows VM through vagrant. However I am not able to see any GUI on the VM.
For example, if I open command prompt in Windows VM and issue command "start chrome.exe", it launches the chrome browser and browser ui is displayed. However if I type the same command through winrm vagrant winrm -c "start chrome.exe", it launches the browser, but ui is not displayed in VM.Same issue happens if I run commands through shell provisioner.
Is there any way, I can run commands from vagrant and the application will be launched in GUI mode in VM?

Is there any way, I can run commands from vagrant and the application will be launched in GUI mode in VM?
No.
From https://msdn.microsoft.com/en-us/library/aa384426(v=vs.85).aspx :
You can use WinRM scripting objects, the WinRM command-line tool, or the Windows Remote Shell command line tool WinRS to obtain management data from local and remote computers ...
winrm is used for Remote Management and does not forward the X window, so no you cannot launch a program like chrome and forward the UI somewhere else.
Your best options to run UI program from your VM :
run from the VM GUI (either by enabling from Vagrantfile or opening the VM from VirtualBox)
running vagrant rdp to login into the VM

The easiest is to run the VM in 'GUI mode' (as opposed to 'headless').
I use VirtualBox from Oracle, which is one of the options easily configured from within your Vagrantfile.
Check out my "Provider-specific configuration" section:
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# # (so we can run the browser)
vb.gui = true
vb.name = "windows10-eval"
# # Customize the amount of memory on the VM:
vb.memory = "2048"
end
When my VM boots I automatically get a GUI which looks exactly as if I was booting a regular Windows machine. This box comes conveniently with chrome already provisioned, but it'd be easy to install it and use it.

Although you can't directly run a GUI app from the WinRM, you can also add a link to your app in the Windows startup so you will ensure the app is ran on system startup.
Add the following in your provisioning script :
mklink C:\Users\vagrant\AppData\Roaming\Microsoft\Windows\"Start Menu"\Programs\Startup\MyApp.link C:\MyApp\\MyApp.exe
shutdown /r /t 1

Related

Is it possible to power-on a VMWare Fusion virtual machine without opening the VMWare application (and other windows)?

I always SSH into my virtual machine and don't use VMWare's virtual machine window/terminal after I am done setting up the VM. I find it annoying to always have the VMWare Fusion application open as well as the VM window, thus, I want to be able to silently start the VM from my terminal and do all other actions only through terminal.
I saw this page on the VMWare website that talks of starting a VM with the command:
/Applications/VMware\ Fusion.app/Contents/Library/vmrun start full/path/of/your/virtual/machine/bundle
That is a step in the right direction as I don't need to click anything to start my VM, however, it still opens the application and VM in windows.
When I used Virtual Box, I remember being able to do this with a command like:
VBoxManage startvm "VM name" --type headless
Is there a similar command that for VMWare that would allow me to run my VM headless?
You can try :
vmrun start full/path/of/your/virtual/machine/bundle nogui

Is it possible to enable WinRM in a Modern.ie VM or Vagrant Box by repackaging it with Packer?

There are these free like free beer virtual machines (VM) from Microsoft which one can download from modern.ie and use for testing or whatever. And there is this nice Gist on Github which explains how to enable WinRM support on that VMs. Unfortunately this requires manual interaction with the VM after initial boot up (step 2. in Gist). Is it possible to let Packer do this job using it´s builder type virtualbox-ovf (VIRTUALBOX BUILDER (FROM AN OVF/OVA))? If it is possible can you provide some example code, please.
Or asked another way: How to create a Vagrant Box from an existing VirtualBox image (.ova file) or from an existing Vagrant Box (.ovffile) with Packer?
What you asked is described in Step 4
Package
Since there's a lot of Windows specific configuration, you can include
the Vagrantfile in the package command so winrm and virtualbox
configuration get's default values when the repackaged is used for
other purposes. Remember to run the command in the same directory the
Vagrantfile resides:
$ vagrant package --output "yourboxname" --Vagrantfile Vagrantfile
After that you're all set!
once you complete step2 and 3, you will run step4 which recreate a vagrant box from the updated VM and you can re-use this box
Or asked another way: How to create a Vagrant Box from an existing VirtualBox image (.ova file) or from an existing Vagrant Box (.ovffile) with Packer?
This is not possible, shortly speaking, packer creates Vagrant box from OS ISO distribution, not from existing VM
You can connect to Windows modern.ie VM with ssh (Openssh service runs at startup). You'll have a very limited shell, but enough to call cmd.exe or powershell, and activate WinRM. On Windows 10 VM, you just have to change the network type to something not public. That's it.

Conifgure VBoxManage commands that require VM be running from Vagrantfile

There are several commands under the VBoxManage umbrella that require the guest machine already be running (e.g. controlvm, guestcontrol) but all the vbox configuration I see in the Vagrantfile happens before the machine has started.
Is there a way in the Vagrantfile to configure the machine after it has started?
The goal of vagrant is to abstract the creation of VM for multiple provider (including VirtualBox) it is not really to provide all manipulation of the VM afterwards and replace the VBoxManage -
If you need to run command after the VM has started and run it from Vagrantfile, I would suggest to look at the vagrant-triggers plugin which :
Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.

vagrant on windows need a second vagrant up

I do have an annoying bug using Vagrant on Windows.
Whenever I do start a new VM (after init or destroy) it will not recognize the Linux VM startup. I need to cancle the command using ctrl-c and kill the Machine in vIrtualBox. The second start or any start after this will work.
Any Idea how to find the root cause for this, or which command is executed during
"[default] Waiting for VM to boot. This can take a few minutes."
Stefan
This can be a few things... the easiest way to tell the exact problem is to see what the VM itself is stalling on by running it in gui mode.
config.vm.provider "virtualbox" do |v|
v.gui = true
end
It could be stuck at the grub prompt or something... it could also just be a bad image... perhaps try a different Vagrant base box.

Sending autotest / guard desktop notifications from Vagrant Ubuntu VM to host (W7 and OS X)

I have a question for all you Vagrants and TDD'ers out there,
How can I make a Vagrant Ubuntu VM send autotest / guard notifications to a Windows 7 or OS X host?
Details:
I'm trying to build my ultimate road-warrior development environment, so that I can jump between computers, OS's, and countries without worrying about reconfiguring my environment all the time. I'm using Vagrant to make disposable VMs that mirror our production environment, and letting me jump from my work computer (Windows 7) to my home computer (OS X) with minimal hassle.
I am trying to configure my Vagrant Ubuntu VM for use with Test-Driven Development (TDD), and make use of autotest / guard utilities to automatically run my tests on save, and display the results as desktop notifications on the host. I run the Vagrant VM in headless mode, so there is no desktop to receive the notifications, so I need them forwarded to the host.
I have a couple of leads, like using Growl's remote notifications (for receiving, but I don't know how to send them from the Ubuntu VM), or hacking Growl, but I thought that this problem must have been addressed by others out there.
Found a way to make it work on Windows 8 host and Ubuntu vagrant box:
Install gem ruby_gntp in rails.
Add to Guardfile:
`notification :gntp, :sticky => false, :host => '192.168.0.77', :port => '23053', :password => 'yourpassword'`
192.168.0.77 is the IP of host machine, you can find it by running ipconfig.
23053 - standard port for growl.
Install growlforwindows and set network subscription to Vagrant box( help)
with host 10.0.2.2, port 23053 and password yourpassword
10.0.2.2 - default IP of vagrant box gataway, you can confirm it by running netstat -rn in vagrant ssh.
Finally you can run guard -p and start tests.
If you get error 'refused', then it's wrong IP in Guardfile, for example this happens if I set gateway IP of windows machine instead of local IP.
If you get error 'Notiffany register filed', then it's wrong ip in growlforwindows.
Well, why don't just forward all the tests' output to a file, then connect via SSH and see the results?
Basically tail -f command comes handy here.

Resources