@echo off setlocal EnableDelayedExpansion chcp 65001 > nul rem //メトリック設定値 set metric=100 rem //管理者権限判定&実行 openfiles > nul 2>&1 if %errorlevel% == 1 ( @powershell start-process "%~0" -verb runas exit ) set classID= set instanceID= set result= rem //クラスキー検索 for /f %%a in ('REG QUERY HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class /f * /k') do ( set tmp=%%a set key=!tmp:~-38,38! rem echo !key! rem //ネットワーク設定キー検索 for /f %%b in ('REG QUERY %%a /f 00* /k 2^>NUL') do ( rem set tmp2=%%b rem echo !tmp2! rem //SoftEther VPNアダプターキー特定 for /f "tokens=1,2*" %%1 in ('REG QUERY %%b 2^>NUL') do ( if %%1 == DriverDesc ( echo "%%3" | find "VPN Client Adapter - VPN" >NUL if not errorlevel 1 ( set classID=!key! ) ) rem //インスタンスID特定 if not "!classID!" == "" ( if %%1 == NetCfgInstanceId ( echo classID=!classID! echo instanceID=%%3 echo metric=!metric! rem //ネットワークアダプタ名取得 for /f "tokens=1,2*" %%4 in ('REG QUERY HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\!classID!\%%3\Connection 2^>NUL') do ( if %%4 == Name ( set adapterName=%%6 echo adapterName=%%6 ) ) rem //メトリック値セット reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%%3 /v "InterfaceMetric" /t REG_DWORD /d %metric% /f set result=1 rem //ネットワークアダプタ再起動 netsh interface set interface name="!adapterName!" disable netsh interface set interface name="!adapterName!" enable set classID= ) ) ) ) ) if not !result! == 1 ( echo; echo VPNクライアントアダプターが見つかりませんでした。 echo; echo 終了するには何かキーを押してください。 pause > nul exit ) echo 設定を完了しました。PCを再起動してください。 pause > nul exit