在 Windows 7 中完全自动化安装 VirtualBox 工具

在 Windows 7 中完全自动化安装 VirtualBox 工具

我正在无人值守地安装 Windows。其中一部分是安装 VirtualBox 客户机附加组件,它由安装程序运行,因为 中有以下条目Autounattend.xml

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
  ...
  <settings pass="oobeSystem">
    ...
    <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="NonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      ...
      <FirstLogonCommands>
        <SynchronousCommand>
          <Order>30</Order>
          <Description>VirtualBox Additions</Description>
          <CommandLine>F:\VBoxWindowsAdditions-x86.exe /S</CommandLine>
        </SynchronousCommand>
        ...

它运行良好,无需 GUI 即可安装。但是,会弹出两个窗口询问是否安装两个设备驱动程序。这对于自动安装来说不是一个好兆头。有没有办法强制 win7 接受驱动程序,或者我可以设置一个注册表项让它信任它们?

答案1

避免这些提示的最佳方法是获取设备驱动程序签名所需的证书,并在安装之前将其安装在客户机上。您可以在本地计算机 -> 受信任的发布者证书存储中找到 Sun 的证书和 Oracle 的证书。您可以轻松地从那里导出它们,然后在安装附加组件之前将它们导入到客户机中。

要从已安装并信任用于使用 PowerShell 签署设备驱动程序的证书的计算机中提取证书:

cd cert:\LocalMachine\TrustedPublisher
$cert = dir | where { $_.Subject -like "*Oracle*" }
$type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
$bytes = $cert.Export($type)
[System.IO.File]::WriteAllBytes("C:\Oracle.cer", $bytes)

您可能希望运行上述命令并替换*Oracle**Sun Microsystems*捕获两个证书,这样它们就可以同时存在,这样您就可以更独立于 VirtualBox 的版本。只需确保在无人值守安装客户机添加程序之前安装这些证书即可。

答案2

补充@Goyuix 的回答,此脚本将导出.cer当前目录中所有以指纹开头的 Oracle 文件名:

$type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
dir cert:\LocalMachine\TrustedPublisher | where { $_.Subject -like "*Oracle*" } | ForEach { [System.IO.File]::WriteAllBytes("vbox_Oracle_" + $_.Thumbprint.Substring(0, 10) + ".cer", $_.Export($type))  }

然后可以使用以下代码片段导入这些cmd内容:

for %%i in (%~dp0\vbox_*.cer) do certutil -addstore -f "TrustedPublisher" %%i

答案3

自从答案写出来后,Oracle 已经添加了一种更清晰的机制来解决这个问题。所需的证书包含在 CD 本身中,以及一个用于将证书导入正确证书存储的实用程序。

假设 ISO 安装为驱动器号 E:您只需在运行安装程序之前将此命令添加到无人值守脚本中:

E:\cert\VBoxCertUtil add-trusted-publisher E:\cert\vbox*.cer --root E:\cert\vbox*.cer

相关内容