Created
December 13, 2013 20:28
-
-
Save dansmith65/7950823 to your computer and use it in GitHub Desktop.
Fix issue with VirtualBox Host-Only Network adapter in Windows by adding *NdisDeviceType=1 to registry.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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