如何使用脚本来控制 VirtualBox 来宾?

The*_*666 5 virtualbox

请参阅:从 Ubuntu 桌面在 Windows 中启动应用程序

我想知道 Takkat 是否可以详细说明实际执行,即脚本文件中的 howto。

这将非常有帮助。提前致谢

我的脚本文件 InternetExplorerVM.sh 看起来像这样,执行是

/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
Run Code Online (Sandbox Code Playgroud)

对于任何错误,我深表歉意,这是我第一次在 askubuntu 上发帖。提前致谢。这非常有帮助。BNSF 来宾需要这个,他们的大型机模拟器专门在支持 Java 的 Internet Explorer 上运行。

Sly*_*Sly 3

他基本上是说你可以这样做:

  1. 创建虚拟机,如 Windows 虚拟机。
  2. 登录虚拟机。
  3. 将虚拟机切换到“无缝”模式
  4. 在 Virtual Box 主窗口中保存虚拟机的状态。
  5. 使用命令创建 bash 脚本VBoxManage,以便您可以执行类似的操作./runinwindows "C:\\some\\path\\executable.exe"

例如:

#!/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
Run Code Online (Sandbox Code Playgroud)

然后,您可以在终端中运行 Windows 可执行文件(在本例中),但它实际上是在虚拟机中运行。