【问题标题】:Run program on guest OS in VirtualBox在 VirtualBox 的来宾操作系统上运行程序
【发布时间】:2016-07-14 06:20:39
【问题描述】:

我在 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_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

机器启动良好,但我无法运行任何程序,因为出现以下错误:

Traceback(最近一次调用最后一次):文件“runonguest.py”,第 39 行,在 gs = session.console.guest.create_session('win7', '') 文件 "/usr/local/lib/python2.7/dist-packages/virtualbox/library_ext/guest.py", 第 24 行,在 create_session 中 raise SystemError("GuestSession 启动失败") SystemError: GuestSession 启动失败

在我尝试使用命令行在客户机上运行程序之后。所以我正在运行虚拟机,并尝试执行以下命令:

VBoxManage guestcontrol "Windows7" --username win7 run --exe C:\Windows\System32\cmd.exe  --wait-stdout  -- "C:\Windows\System32\cmd.exe" "/C" "tasklist"

但它给我带来了下一个错误:

VBoxManage:错误:VERR_ACCOUNT_RESTRICTED VBoxManage:错误:详细信息: 代码 VBOX_E_IPRT_ERROR (0x80bb0005),组件 GuestSessionWrap, 接口 IGuestSession,被调用者 nsISupports VBoxManage:错误: 上下文:“WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags),30 * 1000, &enmWaitResult)" 在文件 VBoxManageGuestCtrl.cpp 的第 938 行

我一直在寻找可能的解决方案,但其中大多数是针对旧版本的 VirtualBox,其中命令 run 根本不存在。 如果有人知道任何可能的解决方案,那就太好了。 谢谢。

【问题讨论】:

    标签: python virtual-machine command-line-interface virtualbox


    【解决方案1】:

    访问 [开始菜单] 并在 [搜索程序和文件] 中键入 运行。 在 [Run line] 中键入 gpedit.msc。 在那里,转到 Windows 设置 -> 安全设置 -> 本地策略 -> 安全选项 -> [帐户:将本地帐户使用空白密码限制为仅控制台登录] 并将其设置为 已禁用。重启VM后,应该可以解决了。

    【讨论】:

    • 谢谢。我什至没有朝那个方向思考。它现在工作得很好。
    • 我当时也没有遇到这个问题:)
    【解决方案2】:

    到目前为止,我设法在 VirtualBox 的来宾操作系统上启动程序。 该解决方案基于(我看到的未记录)事实,即在用户帐户没有密码的情况下,VBox API 不会启动会话。所以我在访客的 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
    ......
    

    发布详情:

    python 2.7.6
    pyvbox 1.0.0
    主机操作系统 - Ubuntu 14.04
    来宾操作系统 - Windows7 x32

    虚拟盒子 5.0.16

    UPD:根据 iugene 的回答,真正的解决方案是在 Windows 安全策略中。

    访问 [开始菜单] 并在 [搜索程序和文件] 中键入运行。里面 [运行行] 键入 gpedit.msc。在那里,转到 Windows 设置 -> 安全 设置 -> 本地策略 -> 安全选项 -> [帐户:限制 本地帐户使用空白密码仅用于控制台登录]并设置它 禁用。重启VM后,应该可以解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-21
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 2020-09-03
      • 2010-11-12
      相关资源
      最近更新 更多