Correct way to install VirtualBox from electron app on windows

Viewed 287

I'm trying to install VirtualBox from an electron app to the host machine.

Currently I do the following:

(virtualbox installer is packaged in the electron app)

await util.sudoExec(`
  copy ${app.getAppPath()}\\..\\resources\\installers\\VirtualBox-6.1.8-137981-Win.exe ${temp}\\pkg.exe &
  ${temp}\\pkg.exe /extract --silent &
  msiexec /i ${temp}\\VirtualBox\\VirtualBox-6.1.8-r137981.msi /quiet /norestart ALLUSERS=2 VBOX_INSTALLDESKTOPSHORTCUT=0 VBOX_INSTALLQUICKLAUCHSHORTCUT=0
`)

The above code is working 70%. In some cases I got an error message ie.:

'C:\Users\Username\AppData\Local\Temp\pkg.exe' is not recognized as an internal or external command,
operable program or batch file.

I'm not sure this is the best way to install VB.

2 Answers

You could try to use Chocolatey:

This will install it:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

And this command will install Virtualbox:

choco install virtualbox -y

This would also allow you to easily update the software whenever you need to. It's an option so you don't need to maintain package installers for each version of VB.

Related