Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix issue with VirtualBox Host-Only Network adapter in Windows by adding *NdisDeviceType=1 to registry.
@ECHO OFF
ECHO.-------------------------------------------------------------------------------
ECHO.
ECHO. VirtualBoxFixNIC.cmd
ECHO.
ECHO. Created on 2013-DEC-13 by Dan Smith http://scr.im/dansmith
ECHO.
ECHO. Fix issue with VirtualBox Host-Only Network adapter in Windows by adding
ECHO. *NdisDeviceType=1 to registry.
ECHO.
ECHO.-------------------------------------------------------------------------------
ECHO.
:: https://forums.virtualbox.org/viewtopic.php?f=1&t=27924
:: http://msdn.microsoft.com/en-us/library/ff557037%28VS.85%29.aspx
SETLOCAL EnableDelayedExpansion
:: SET VARIABLES
:: nicRegKey is the reg key containing all NIC's
SET nicRegKey=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
SET nicRegKeyLength=96
:: driverDesc is the value to find in the registry
SET driverDesc="VirtualBox Host-Only Ethernet Adapter"
:: interfaceName is the name of the VB NIC in: Control Panel\Network and Internet\Network Connections
SET interfaceName="VirtualBox Host-Only Network"
:: FIND REG KEY
SET /A i=0
FOR /F "usebackq delims=" %%a IN (`REG QUERY %nicRegKey% /s /t REG_SZ /f %driverDesc%`) DO (
SET string=%%a
IF "!string:~0,%nicRegKeyLength%!"=="%nicRegKey%" (
SET /A i=!i! + 1
SET nicRegKeyVB=!string!
)
)
:: CHECK IF *NDISDEVICETYPE EXISTS FOR REG KEY
IF "%i%"=="1" (
REG QUERY %nicRegKeyVB% -v *NdisDeviceType >NUL
IF NOT ERRORLEVEL 1 (
SET errorMessage=REGISTRY NOT UPDATED: *NdisDeviceType already exists
)
) ELSE (
SET errorMessage=REGISTRY NOT UPDATED: %i% reg key's found
)
:: ADD REG KEY
IF NOT DEFINED errorMessage (
ECHO.adding registry key to:
ECHO.%nicRegKeyVB%
REG ADD %nicRegKeyVB% -v *NdisDeviceType /t REG_DWORD /d 1
IF ERRORLEVEL 1 (
SET errorMessage=an error occured when adding the key to the registry
) ELSE (
ECHO.disable/enable NIC:
NETSH INTERFACE SET INTERFACE name=%interfaceName% admin=disabled
NETSH INTERFACE SET INTERFACE name=%interfaceName% admin=enabled
)
)
:: SHOW RESULT TO USER
ECHO.
ECHO.%errorMessage%
ECHO.
PAUSE
ENDLOCAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.