Skip to content

Instantly share code, notes, and snippets.

@badrelmers
Last active May 1, 2024 10:10
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save badrelmers/20990cd518fed05e5f171961c63e85ba to your computer and use it in GitHub Desktop.
Save badrelmers/20990cd518fed05e5f171961c63e85ba to your computer and use it in GitHub Desktop.
portable virtualbox using the latest virtualbox installers

This makes virtualbox works in a portable mode:

  • if you have any installed virtualbox then uninstall it first
  • download https://download.virtualbox.org/virtualbox/7.0.8/VirtualBox-7.0.8-156879-Win.exe or any newer or older version
  • click on Download ZIP above to download the scripts needed
  • create a folder inside your USB/external drive or whatever, name it myVMBOX (ex. F:\myVMBOX if your USB is in F:\).
  • inside F:\myVMBOX put the virtualbox exe we just downloaded (VirtualBox-7.0.8-156879-Win.exe) and rename it to VirtualBox.exe.
  • inside F:\myVMBOX put the following files start_virtualbox.bat and uninstall_virtualbox.bat, you will find them inside the zip you just downloaded.
  • now everytime you want to start virtualbox use start_virtualbox.bat.

If you want to uninstall virtualbox use the Control Panel or uninstall_virtualbox.bat (this is optional).

That is all, now everytime you start virtualbox using start_virtualbox.bat it will start in a portable mode, the virtual machines we create will be saved to F:\myVMBOX inside your USB, and you can use the USB in any machine now, virtualbox will always find your virtual machines from your USB, but you have to always start virtualbox from start_virtualbox.bat.

If you download a newer virtualbox executable, then uninstall the old one and do the same steps again.

tip:

if you want to migrate your old created virtual machines to the new portable folder myVMBOX (for example your old virtual machines created with virtualbox), do the following:

  • start virtualbox using start_virtualbox.bat.
  • now close the virtualbox we just started.
  • open c:\myVMBOX folder (c:\myVMBOX is just a symlink shortcut to your USB folder F:\myVMBOX), you have to open c:\myVMBOX for this trick to work not F:\myVMBOX.
  • inside c:\myVMBOX create a folder and name it Machines if it does not already exist.
  • now inside c:\myVMBOX\Machines put all your old virtual machines folders, so you will have at the end something like that for example:
c:\myVMBOX\Machines\win10VM
c:\myVMBOX\Machines\win7VM
c:\myVMBOX\Machines\UbuntuVM
  • now enter to every folder inside c:\myVMBOX\Machines and doble click the file that ends with .vbox extension (it have a blue icon).

that is all, all your older virtual machines are now registred in virtualbox database and are saved inside your USB. you will find them inside your USB F:\myVMBOX.

this gist was created for this discussion: vboxme/Portable-VirtualBox#89 (comment)

@echo off
setlocal
pushd %~pd0
:: ###################################################################
:: please configure this if your VirtualBox exe have a different name
:: ###################################################################
set "VirtualBox_installer=VirtualBox.exe"
:: ###################################################################
:: from here you do not need to change anything
:: ###################################################################
set "install_dir=c:\myVirtualBox"
echo.
IF NOT EXIST "%VirtualBox_installer%" ( color 4F & echo. & echo %VirtualBox_installer% was not found, if you downloaded a new installer or changed its name then please change this script to point to the new installer, you have to change VirtualBox_installer line. & echo. & pause & exit /b )
set "portable_dir_name=myVMBOX"
set "VBOX_symlink=c:\%portable_dir_name%"
set "VBOX_Real=%~dp0%portable_dir_name%"
mkdir "%VBOX_Real%" 2>nul
rem never use rd /S it will delete the real dir content if it was created with junction.exe in xp
IF EXIST "%VBOX_symlink%" rd /Q "%VBOX_symlink%"
mklink /J "%VBOX_symlink%" "%VBOX_Real%" >nul
setx VBOX_USER_HOME c:\%portable_dir_name% >nul
set "VBOX_USER_HOME=c:\%portable_dir_name%"
IF NOT EXIST "%install_dir%\VirtualBox.exe" call :install
"%install_dir%\VBoxManage.exe" setproperty machinefolder "c:\%portable_dir_name%\Machines"
echo starting VirtualBox...
start "VirtualBox" "%install_dir%\VirtualBox.exe"
echo.
echo.
echo.
echo exiting in 7s
timeout 7
rem pause
exit /b
:install
tasklist /fi "ImageName eq VirtualBox.exe" /fo csv 2>NUL | find /I "VirtualBox.exe">NUL
if "%ERRORLEVEL%"=="0" set dirty_install=yes
tasklist /fi "ImageName eq VBoxSDS.exe" /fo csv 2>NUL | find /I "VBoxSDS.exe">NUL
if "%ERRORLEVEL%"=="0" set dirty_install=yes
tasklist /fi "ImageName eq VBoxSVC.exe" /fo csv 2>NUL | find /I "VBoxSVC.exe">NUL
if "%ERRORLEVEL%"=="0" set dirty_install=yes
IF EXIST "%ProgramFiles%\Oracle\VirtualBox\VirtualBox.exe" set dirty_install=yes
IF EXIST "%ProgramFiles(x86)%\Oracle\VirtualBox\VirtualBox.exe" set dirty_install=yes
if [%dirty_install%]==[yes] (
color 4F & echo.
echo VirtualBox is already installed or you are running a portable virtualbox.
echo only one virtualbox can run at the same time, and there should not be more
echo than one installed virtualbox. if you have virtualbox installed please
echo uninstall it first, and if you are running a Portable virtualbox then stop
echo it first, and run this script again. exiting...
echo. & pause & exit
)
echo installing VirtualBox, please wait...
"%VirtualBox_installer%" --silent --ignore-reboot --msiparams "INSTALLDIR=""%install_dir%""" VBOX_INSTALLDESKTOPSHORTCUT=0 VBOX_INSTALLQUICKLAUNCHSHORTCUT=0 VBOX_START=0
IF NOT EXIST "%install_dir%\VirtualBox.exe" ( color 4F & echo. & echo %install_dir%\VirtualBox.exe was not found, VirtualBox could not be installed. exiting... & echo. & pause & exit )
echo VirtualBox was installed
exit /b
@echo off
setlocal
pushd %~pd0
:: ###################################################################
:: please configure this if your VirtualBox exe have a different name
:: ###################################################################
set "VirtualBox_installer=VirtualBox.exe"
:: ###################################################################
:: from here you do not need to change anything
:: ###################################################################
set "install_dir=c:\myVirtualBox"
echo.
IF NOT EXIST "%VirtualBox_installer%" ( color 4F & echo. & echo %VirtualBox_installer% was not found, if you downloaded a new installer or changed its name then please change this script to point to the new installer, you have to change VirtualBox_installer line. & echo. & pause & exit /b )
tasklist /fi "ImageName eq VirtualBox.exe" /fo csv 2>NUL | find /I "VirtualBox.exe">NUL
if "%ERRORLEVEL%"=="0" set VirtualBoxrunning=yes
tasklist /fi "ImageName eq VBoxSDS.exe" /fo csv 2>NUL | find /I "VBoxSDS.exe">NUL
if "%ERRORLEVEL%"=="0" set VirtualBoxrunning=yes
tasklist /fi "ImageName eq VBoxSVC.exe" /fo csv 2>NUL | find /I "VBoxSVC.exe">NUL
if "%ERRORLEVEL%"=="0" set VirtualBoxrunning=yes
if [%VirtualBoxrunning%]==[yes] (
color 4F & echo.
echo VirtualBox is running. please stop it first. exiting...
echo. & pause & exit
)
echo uninstalling VirtualBox, please wait...
IF EXIST "%~pd0extractedinstaller" rmdir /Q /S "%~pd0extractedinstaller"
"%VirtualBox_installer%" --silent --extract --path "%~pd0extractedinstaller" >nul
pushd "%~pd0extractedinstaller"
REM FOR /f "tokens=*" %%G IN ('dir /b VirtualBox*.msi') DO start "VirtualBoxremove" /wait MsiExec.exe /norestart /uninstall "%%G" /quiet
FOR /f "tokens=*" %%G IN ('dir /b VirtualBox*.msi') DO start "VirtualBoxremove" /wait MsiExec.exe /norestart /uninstall "%%G"
popd
rmdir /Q /S "%~pd0extractedinstaller"
IF EXIST "%install_dir%\VirtualBox.exe" ( color 4F & echo. & echo %install_dir%\VirtualBox.exe was not uninstalled. run me again or uninstall it from the Control Panel & echo. & pause & exit )
setx VBOX_USER_HOME "" >nul
reg delete HKEY_CURRENT_USER\Environment /v VBOX_USER_HOME /f >nul
echo.
echo VirtualBox was uninstalled
echo.
echo.
echo.
echo exiting in 7s
timeout 7
REM pause
@p060477
Copy link

p060477 commented Jul 20, 2023

Hi Badr, seems new virtualbox vers, 7.0.10 , has been issued...
so how to update also your portable vers.?
i think we should have to dl the installer .exe :
VirtualBox-7.0.10-158379-Win.exe
and modify the start/unistal .bat....but how to without makin disasters...??
we ask cause we are champion of the world of disasters...any....... :(

@badrelmers
Copy link
Author

@p060477 hello bro, I hope you are fine

so how to update also your portable vers.?

I changed the scripts to be easier to update virtualbox:

  • uninstall virtualbox using Control Panel or uninstall_virtualbox.bat
  • download the new scripts using the Download ZIP in the top of this page
  • delete the old scripts you have
  • download the new virtualbox executable and rename it to VirtualBox.exe
  • inside F:\myVMBOX put the virtualbox exe we just downloaded VirtualBox.exe and the 2 scripts from Download ZIP
  • start start_virtualbox.bat as always

you do not need to change anything in both scripts start_virtualbox.bat and uninstall_virtualbox.bat

that s all

have a good day

@p060477
Copy link

p060477 commented Jul 21, 2023

Hi Badr,
i really would like to have had a bro like you...my whole life should be much more easy...anyway:
all work fine thxs!
you have made the updating process so very very smoothy and easy...also for a hard headed donkey like me.. ;) :)
i'd like to make you some ,maybe stupid,questions (as a donkey like me...) :

  1. ext pack remains the 7.0.8 so i had to unistall and install the newest 7.0.10 is it correct?
  2. and what about the GA...do you suggest me not to change the old ones i have?
    ..remind the conflict with win xp guest vm...
    or you are confident in the new ones, 7.0.10 guest additions, and you invite me to use them...??
    Have a nice day you too!!
    Thxs so much indeed in adv
    also for yr so kind patience...
    cheers

@badrelmers
Copy link
Author

ext pack remains the 7.0.8 so i had to unistall and install the newest 7.0.10 is it correct?

if there is ext pack 7.0.10 then just install it if you need it, but in general it is not needed, i never install it

or you are confident in the new ones, 7.0.10 guest additions, and you invite me to use them...??

I don t know, you have to test to see if the old problems were solved.

@p060477
Copy link

p060477 commented Jul 21, 2023

thxs so much dear bro!
cheers :)

@badrelmers
Copy link
Author

you are welcome bro

@p060477
Copy link

p060477 commented Oct 19, 2023

hi Badr, the new 7.0.12 vers has issued
so if i've understood i should have to dl it, rename to virtualbox.exe
then start yr unistall.bat and then start.bat...am i wrong?...
a silly question...: but if i simly renamed my old 7.0.10 vers to virtualbox_old.exe....??
so in my folder i should have it and the new virtualbox.exe (vers 7.0.12) and i easly will be able to switch from the new 7.0.12 to the old 7.0.10...have i say a very big silly thing...??
and another couriosity..: why you said ext pack is not needed...??...i thought it was important for VB and its working fine
...so why you do not mind about extentsion pack...??
apologize me again for my very few and bad level and skills...
cheers

@badrelmers
Copy link
Author

badrelmers commented Dec 15, 2023

hello bro,

then start yr unistall.bat and then start.bat...am i wrong?...

you are correct

have i say a very big silly thing...??

this is fine, organisation is good

...so why you do not mind about extentsion pack...??

because it is not needed generally , it adds some options which are never used by the end user in general, you can read more about those options here: https://www.virtualbox.org/manual/ch01.html#intro-installing

take care

@sixgodfan
Copy link

Why does the computer reboot directly after starting start.bat?

@p060477
Copy link

p060477 commented Jan 8, 2024

hello bro,

then start yr unistall.bat and then start.bat...am i wrong?...

you are correct

have i say a very big silly thing...??

this is fine, organisation is good

...so why you do not mind about extentsion pack...??

because it is not needed generally , it adds some options which are never used by the end user in general, you can read more about those options here: https://www.virtualbox.org/manual/ch01.html#intro-installing

take care

hello my dear bro
you are always king,helpful, and very very patienceable
wish you all the best and more!

@p060477
Copy link

p060477 commented Feb 27, 2024

Hi Badr!
what you think about this...:
https://portableapps.com/node/70284
do you think is worth to give it a try...??
thxs in adv for yr kind attn
cheers!

@badrelmers
Copy link
Author

@sixgodfan you can read the code, it does not use any command to restart the system!

@badrelmers
Copy link
Author

@p060477 helllo bro,

do you think is worth to give it a try...??

i did not test it, and i will not use it because it is closed source, i prefer open source to see what they do... :)

@p060477
Copy link

p060477 commented Mar 13, 2024

@p060477 helllo bro,

do you think is worth to give it a try...??

i did not test it, and i will not use it because it is closed source, i prefer open source to see what they do... :)

thxs my dear bro,
you are right!
As always!
Thxs so much indeed for yr kind attn!
cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment