3

我已经在我的 Mac 上安装了 vagrant 和 virtual box。我创建了一个 Windows10 虚拟机,并使用 winrm 进行了配置。

我可以通过 vagrant 在 Windows VM 上运行命令。但是我无法在 VM 上看到任何 GUI。

例如,如果我在 Windows VM 中打开命令提示符并发出命令“start chrome.exe”,它会启动 chrome 浏览器并显示浏览器 ui。但是,如果我通过 winrm 键入相同的命令vagrant winrm -c "start chrome.exe",它会启动浏览器,但 ui 不会显示在 VM 中。如果我通过 shell 配置程序运行命令,则会发生同样的问题。

有什么办法,我可以从 vagrant 运行命令,并且应用程序将在 VM 中以 GUI 模式启动?

4

3 回答 3

1

有什么办法,我可以从 vagrant 运行命令,并且应用程序将在 VM 中以 GUI 模式启动?

不。

来自https://msdn.microsoft.com/en-us/library/aa384426(v=vs.85).aspx

您可以使用 WinRM 脚本对象、WinRM 命令行工具或 Windows Remote Shell 命令行工具 WinRS 从本地和远程计算机获取管理数据...

winrm 用于远程管理,不转发 X 窗口,所以不,你不能启动像 chrome 这样的程序并将 UI 转发到其他地方。

从 VM 运行 UI 程序的最佳选择:

  • 从 VM GUI 运行(通过从 Vagrantfile 启用或从 VirtualBox 打开 VM)
  • 运行vagrant rdp登录到虚拟机
于 2016-08-22T13:27:52.353 回答
0

最简单的方法是以“GUI 模式”(而不是“无头”模式)运行 VM。我使用 Oracle 的 VirtualBox,这是在 Vagrantfile 中轻松配置的选项之一。

查看我的“提供商特定配置”部分:

  # 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

当我的虚拟机启动时,我会自动获得一个 GUI,它看起来就像我在启动一台普通的 Windows 机器一样。这个盒子很方便地配备了已经配置好的 chrome,但安装和使用它很容易。

于 2018-08-08T00:40:48.877 回答
0

尽管您不能直接从 WinRM 运行 GUI 应用程序,但您也可以在 Windows 启动时添加指向您的应用程序的链接,这样您将确保该应用程序在系统启动时运行。

在您的配置脚本中添加以下内容:

mklink C:\Users\vagrant\AppData\Roaming\Microsoft\Windows\"Start Menu"\Programs\Startup\MyApp.link C:\MyApp\\MyApp.exe
shutdown /r /t 1
于 2020-10-29T13:56:01.657 回答