3

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?

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139

3 Answers3

2

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
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • You can add a link to your app on the Window's start up, then it will be ran on vm startup. – arturn Oct 29 '20 at 13:51
0

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.

0

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
arturn
  • 725
  • 2
  • 11
  • 25