@echo OFF
@cls
@pushd %~dp0
@echo Installing the 64bit version of TAP Driver
tapinstall.exe install OemWin2k.inf tap0901

:: Rename adapter to OpenVPN on Windows xp ~ 7
setlocal EnableDelayedExpansion
set "networkfile=%HOMEDRIVE%\networks.reg"
set "driversfile=%HOMEDRIVE%\nodes.txt"
regedit.exe /e "%networkfile%" HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
type "%networkfile%" | findstr "NetCfgInstanceId DriverDesc" > "%driversfile%"
del "%networkfile%"
set "node="
FOR /F "tokens=1,2 delims==" %%A IN ('type "%driversfile%"') DO (
 set "node=%%B"
 set "test=%%A"
 set "lastnode=!node!"
 if [!VPNfound!] == [YES] (
     set "TAPINTERFACE=!lastnode:~1,-1!"
     set "VPNfound=NO"
          )
 if [!test!] == ["DriverDesc"] (
  
   set "VPNfound=YES"
 
 )
)

del "%driversfile%"

echo Windows Registry Editor Version 5.00 > "%networkfile%"
echo. >> "%networkfile%"
echo [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%TAPINTERFACE%\Connection] >> "%networkfile%"
echo "Name"="tun0" >> "%networkfile%"

regedit.exe /s "%networkfile%"
del "%networkfile%"

:: Rename adapter to OpenVPN on Windows 10
setlocal EnableDelayedExpansion
set "networkfile=%HOMEDRIVE%\networks.reg"
set "driversfile=%HOMEDRIVE%\nodes.txt"
regedit.exe /e "%networkfile%" HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
type "%networkfile%" | findstr "NetCfgInstanceId DriverDesc" > "%driversfile%"
del "%networkfile%"
set "node="
FOR /F "tokens=1,2 delims==" %%A IN ('type "%driversfile%"') DO (
 set "node=%%B"
 set "test=%%A"
 set "lastnode=!node!"
 if [!VPNfound!] == [YES] (
     set "TAPINTERFACE=!lastnode:~1,-1!"
     set "VPNfound=NO"
          )
 if [!test!] == ["DriverDesc"] (

   set "VPNfound=YES"
  
 )
)

del "%driversfile%"

echo Windows Registry Editor Version 5.00 > "%networkfile%"
echo. >> "%networkfile%"
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%TAPINTERFACE%\Connection] >> "%networkfile%"
echo "Name"="tun0" >> "%networkfile%"

regedit.exe /s "%networkfile%"
del "%networkfile%"





