【问题标题】:How to run gui application on windows vm?如何在 windows vm 上运行 gui 应用程序?
【发布时间】:2020-10-29 21:56:01
【问题描述】:

我已经在我的 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 模式启动?

【问题讨论】:

    标签: vagrant vagrant-windows vagrant-plugin


    【解决方案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 登录虚拟机

    【讨论】:

    • 您可以在Window启动时添加一个链接到您的应用程序,然后它将在vm启动时运行。
    【解决方案2】:

    最简单的方法是以“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,但它很容易安装和使用。

    【讨论】:

      【解决方案3】:

      虽然您不能直接从 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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-07
        • 2023-03-05
        • 2013-03-19
        • 2010-09-08
        • 2014-01-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多