Python 在VirtualBox中的来宾操作系统上运行程序
我正在Ubuntu 14.04上运行VirtualBox 5.0.16。我有32位版本Windows7的虚拟机。我要做的是在来宾机上运行程序。首先,我尝试使用Python脚本实现此目的:Python 在VirtualBox中的来宾操作系统上运行程序,python,virtual-machine,command-line-interface,virtualbox,Python,Virtual Machine,Command Line Interface,Virtualbox,我正在Ubuntu 14.04上运行VirtualBox 5.0.16。我有32位版本Windows7的虚拟机。我要做的是在来宾机上运行程序。首先,我尝试使用Python脚本实现此目的: vbox = virtualbox.VirtualBox() session = virtualbox.Session() vm = vbox.find_machine('Windows7') vm.launch_vm_process(session, 'gui', '').wait_for_completio
vbox = virtualbox.VirtualBox()
session = virtualbox.Session()
vm = vbox.find_machine('Windows7')
vm.launch_vm_process(session, 'gui', '').wait_for_completion()
session = vm.create_session()
time.sleep(35)
gs = session.console.guest.create_session('win7', '')
process, stdout, stderr = gs.execute('C:\\Windows\\System32\\cmd.exe', ['/C', 'tasklist'])
print stdout
机器启动良好,但我无法运行任何程序,因为出现以下错误:
回溯最近一次调用:文件runonguest.py,第39行,在
gs=session.console.guest.create_session'win7',File/usr/local/lib/python2.7/dist-packages/virtualbox/library_ext/guest.py,
第24行,在创建会话中
raise SystemErrorGuestSession无法启动系统错误:GuestSession无法启动
在我尝试使用命令行在来宾机上运行程序之后。所以我运行虚拟机,并尝试执行以下命令:
VBoxManage guestcontrol "Windows7" --username win7 run --exe C:\Windows\System32\cmd.exe --wait-stdout -- "C:\Windows\System32\cmd.exe" "/C" "tasklist"
但这给我带来了下一个错误:
VBoxManage:错误:VERR\u帐户\u受限VBoxManage:错误:详细信息:
代码VBOX_E_IPRT_错误0x80bb0005,组件GuestSessionWrap,
接口iGetSession,被调用方支持VBoxManage:错误:
上下文:WaitForArraycomsaferrayasinParamessionWaitFlags,30*
1000,&enmWaitResult位于文件VBoxManageGuestCtrl.cpp的第938行
我一直在寻找可能的解决方案,但大多数都是针对旧版本的VirtualBox,其中根本不存在命令运行。
如果有人知道任何可能的解决办法,那就太好了。
谢谢。到目前为止,我成功地在VirtualBox的来宾操作系统上启动了该程序。 该解决方案基于我看到的未记录的事实,即VBOXAPI在用户帐户没有密码的情况下不会启动会话。所以我在guest的Windows7上用密码创建了一个新的用户帐户 对于Python,只需编写:
In [15]: gs = session.console.guest.create_session('user', 'user')
In [16]: process, stdout, stderr = gs.execute('C:\\Windows\\System32\\cmd.exe', ['/C', 'tasklist'])
In [17]: print stdout
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 12 K
System 4 Services 0 528 K
smss.exe 264 Services 0 688 K
csrss.exe 340 Services 0 2,824 K
wininit.exe 388 Services 0 3,128 K
csrss.exe 400 1 3,572 K
winlogon.exe 440 1 5,556 K
.....
VBoxManage guestcontrol "Windows7" --verbose --username user --password user run --exe "C:\\
Windows\\System32\\cmd.exe" -- cmd.exe /c tasklist
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 12 K
System 4 Services 0 532 K
smss.exe 264 Services 0 688 K
csrss.exe 340 Services 0 2,848 K
wininit.exe 388 Services 0 3,128 K
csrss.exe 400 1 3,572 K
winlogon.exe 440 1 5,556 K
......
对于控制台使用,只需编写:
In [15]: gs = session.console.guest.create_session('user', 'user')
In [16]: process, stdout, stderr = gs.execute('C:\\Windows\\System32\\cmd.exe', ['/C', 'tasklist'])
In [17]: print stdout
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 12 K
System 4 Services 0 528 K
smss.exe 264 Services 0 688 K
csrss.exe 340 Services 0 2,824 K
wininit.exe 388 Services 0 3,128 K
csrss.exe 400 1 3,572 K
winlogon.exe 440 1 5,556 K
.....
VBoxManage guestcontrol "Windows7" --verbose --username user --password user run --exe "C:\\
Windows\\System32\\cmd.exe" -- cmd.exe /c tasklist
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 12 K
System 4 Services 0 532 K
smss.exe 264 Services 0 688 K
csrss.exe 340 Services 0 2,848 K
wininit.exe 388 Services 0 3,128 K
csrss.exe 400 1 3,572 K
winlogon.exe 440 1 5,556 K
......
发布详情:
python 2.7.6
pyvbox 1.0.0
主机操作系统-Ubuntu 14.04
来宾操作系统-Windows7 x32
VirtualBox 5.0.16
UPD:根据iugene的回答,真正的解决方案是Windows安全策略
进入[开始菜单]并在[搜索程序和文件]中键入Run。在…内 [运行行]键入gpedit.msc。在那里,转到Windows设置->安全性 设置->本地策略->安全选项->[帐户:限制] 本地帐户使用空密码[仅用于控制台登录]并进行设置 给残疾人。VM重启后,应解决此问题
进入[开始菜单]并在[搜索程序和文件]中键入Run。 在[Run line]内键入gpedit.msc。
在那里,转到Windows设置->安全设置->本地策略->安全选项->[帐户:限制本地帐户使用空白密码,仅用于控制台登录],然后将其设置为禁用。VM重新启动后,应解决此问题。谢谢。我甚至没有朝那个方向想。现在一切正常。我当时也没有遇到这个问题: