重裝網卡驅動後,Windows 會建立新的網路連線介面,名稱自動遞增為「區域連線 2」、「區域連線 3」……舊的「區域連線」雖隱藏但仍殘留註冊表設定。若新介面設定相同 IP,系統會彈出「IP 位址已被其他介面使用」警告。
regedit → Enter。HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}Connection,右側 Name 值即可確認對應名稱。$netKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}'
$items = Get-ChildItem $netKey
foreach ($item in $items) {
$connKey = "$netKey\$($item.PSChildName)\Connection"
if (Test-Path $connKey) {
$name = Get-ItemProperty $connKey -Name Name -ErrorAction SilentlyContinue
if ($name.Name -eq '區域連線') { Remove-Item $item.PSPath -Recurse -Force; Write-Host "已刪除舊介面 $($item.PSChildName)" }
}
}
Write-Host "完成,請重新啟用網卡或重開機。"