virtualbox vboxmanage hostonlyif network without rebooting

Discussions related to using VirtualBox on Windows hosts.
Post Reply
bojac
Posts: 1
Joined: 20. Jul 2020, 10:36

virtualbox vboxmanage hostonlyif network without rebooting

Post by bojac »

Hi all,

I use a Batch script to create a VM along with its network adapter :
Here are the main commands :

set VM=my-vm
set IP=192.168.50.100
set VDI=myvm_vbox_vdi_x64.vdi
set VBM="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
set VMPATH=C:\Home\VMS\%VDI%

REM create a new Ethernet adapter
%VBM% hostonlyif create

REM The creation of an Ethernet adapter seems to me stupid in its logic, because there is no way to my knowledge to properly retrieve the name of the new adapter created using the VBoxManage command,
REM which also requires this same name to change the configuration of the adapter. It seems that the designers never tested this possibility!
REM Nevertheless with lots of tricks, we still manage it, but without the help of VBoxManage. This makes the code heavier and hinders portability.

REM Get the Ethernet adapter name -> NETNAME
%VBM% hostonlyif ipconfig "%NETNAME%" --ip "%IP%"

REM create the VM
%VBM% createvm --name %VM% --ostype "RedHat_64" --register
%VBM% storagectl %VM% --name "SATA Controller" --add sata --controller IntelAHCI
%VBM% storageattach %VM% --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "%VMPATH%"
%VBM% modifyvm %VM% --ioapic on
%VBM% modifyvm %VM% --boot1 disk --boot2 none
%VBM% modifyvm %VM% --memory 2028 --vram 16 --cpus 2
%VBM% modifyvm %VM% --nic1 nat --cableconnected1 on
%VBM% modifyvm %VM% --nic2 hostonly --hostonlyadapter2 "%NETNAME%"

When opening the VirtualBox GUI, all seems OK (Ethernet Adapter + VM), but when I start the VM I obtain an error within a pop window :

Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #3' (VERR_INTNET_FLT_IF_NOT_FOUND).
Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND).

Result Code:
E_FAIL (0x80004005)
Component:
ConsoleWrap
Interface:
IConsole {872da645-4a9b-1727-bee2-5585105b9eed}


After rebooting Windows, it works !!

How to do for this VM creation working without rebooting ?? (needed for automation process)

Thank in advance for your answers
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: virtualbox vboxmanage hostonlyif network without rebooting

Post by scottgus1 »

On Windows, when making a new Host-Only network, UAC asks for permission before making the new Host-Only adapter for the host OS. Running 'vboxmanage hostonlyif create' in the command prompt also asks for UAC permission. Running the command prompt window as Administrator asks for UAC right away, then 'vboxmanage hostonlyif create' succeeds in making a new Host-Only adapter. In all these cases, once UAC is Yes'd, the Host-Only adapter appears.

Try your script Run As Administrator? If it works then, and you don't want to click Yes in UAC, make a RaA task in Task Scheduler that runs the batch file, then launch the task with a shortcut.
bojac wrote:there is no way to my knowledge to properly retrieve the name of the new adapter created using the VBoxManage command,
Could have been an oversight, but there could be a way too. In lieu of a possibly-existing actual command, I would try this:

'vboxmanage hostonlyif create' makes the 0-100% progress bar, then prints this next line:
Interface 'VirtualBox Host-Only Ethernet Adapter #4' was successfully created

Run this line with a > redirect, like this:
vboxmanage hostonlyif create > newhonet.txt

and the "Interface ... was successfully created" line goes into newhonet.txt. Use a batch file 'FOR' to parse the contents of newhonet.txt for single quotes, and output variable 2 will contain the new Host-Only name.
Post Reply