Skip to content

Instantly share code, notes, and snippets.

@Ran-Xing
Last active February 14, 2025 01:28
Show Gist options
  • Save Ran-Xing/084685e5ad85be523c46ca76e4bf927a to your computer and use it in GitHub Desktop.
Save Ran-Xing/084685e5ad85be523c46ca76e4bf927a to your computer and use it in GitHub Desktop.
删除多余的网络适配器,解决强迫症的烦恼,(WLAN 2 WLAN 3 本地连接 2 本地连接 3)

Purpose

The purpose of this script is to help users remove redundant network adapter entries, particularly the frequently appearing duplicates like "WLAN 2," "WLAN 3," "Local Area Connection 2," "Local Area Connection 3," etc. These unnecessary network adapter entries often affect system network management and stability, especially when devices are frequently connected and disconnected. This script allows users to easily remove these entries and resolve the frustration of OCD (Obsessive-Compulsive Disorder) when it comes to network configurations.

Features Overview

  1. Registry Backup: Before performing any changes, the script automatically backs up the registry to ensure that the system can be restored if something goes wrong.
  2. Remove Redundant Network Adapters: The script scans the registry for network configuration entries and deletes any that match predefined naming patterns (e.g., "WLAN," "Ethernet," "Bluetooth Network Connection").
  3. Modify Network Descriptions: Users can optionally modify network description values to better manage network adapters.
  4. Recommended Tools: The script provides links to useful tools for further management and cleanup of network adapters.

Steps to Use

  1. Download the Script: Download the script and ensure it is run with administrator privileges.
  2. Backup Registry: The script will create a backup file on the desktop, which can be restored if necessary.
  3. Delete Network Adapters: The script will scan through the registry for each network adapter entry and prompt the user for confirmation before deleting.
  4. Modify Network Descriptions: Users can set certain network adapter descriptions to a specific value (e.g., "1").
  5. Use Recommended Tools: If the script doesn't resolve the issue, users can try using the recommended tools for further cleaning of redundant network adapters.

Important Notes

  • Backup Data: Although the script backs up the registry, it is recommended to manually back up important data before performing any deletion operations.
  • Driver Installation: When using the device cleanup tool, make sure to download and prepare the network adapter drivers in advance, as you may need to reinstall them after removal.
  • Manual Intervention: If the script is unable to delete certain adapters, users can manually delete entries in the registry or modify adapter names and re-run the script.

Recommended Tools

Disclaimer

  • This script is designed to help users remove redundant network adapter entries to improve system performance. However, since it involves modifying the system registry, users assume full responsibility for any risks associated with using this script. The script will modify system settings, and improper use may lead to irreversible changes or system issues. It is essential to back up your system fully before using this script and ensure you understand the risks involved. The author is not responsible for any damages caused by the use of this script.

Conclusion

With this script, you can easily remove redundant network adapters and improve your system's network management experience, putting an end to the frustration caused by OCD. We recommend making backups before performing any operations and following the prompts to ensure safety.

目的

该脚本的目的是帮助用户删除多余的网络适配器项,尤其是在网络配置中经常会出现的“WLAN 2”、“WLAN 3”、“本地连接 2”、“本地连接 3”等重复项。 这些多余的网络适配器项往往会影响系统的网络管理和稳定性,尤其是当设备经常进行网络连接和断开时。 通过本脚本,用户可以轻松删除这些不必要的项,解决强迫症的烦恼。

功能概述

  1. 备份注册表:在操作之前,脚本会自动备份注册表,确保万一出现问题时可以恢复系统。
  2. 删除多余的网络适配器:脚本会扫描注册表中的网络配置项,并根据名称匹配规则(例如“WLAN”、“以太网”、“蓝牙网络连接”等),删除符合条件的项。
  3. 修改网络描述:脚本允许用户选择性地修改一些网络描述项的值,以便更好地管理网络适配器。
  4. 推荐工具:提供了一些有用的工具推荐,如设备清理工具,帮助用户更彻底地管理网络适配器。

使用步骤

  1. 下载脚本:下载脚本文件,并确保以管理员权限运行。
  2. 备份注册表:脚本会在桌面生成一个注册表备份文件,用户可以在需要时恢复。
  3. 删除网络适配器:脚本会依次扫描注册表中的每个网络适配器项,提供是否删除的选择。
  4. 设置网络描述:用户可以根据需要设置一些网络适配器的描述项的值。
  5. 使用推荐工具:如果脚本无法解决问题,用户可以尝试使用推荐的工具进一步清理多余的网络适配器。

注意事项

  • 备份数据:虽然脚本会进行备份,但在执行任何删除操作时,建议先手动备份关键数据。
  • 驱动程序:在使用设备清理工具时,确保提前下载并准备好网卡驱动程序,以便卸载后重新安装。
  • 手动操作:如果脚本无法删除某些适配器,可以通过注册表手动删除,或者修改适配器名称再重新运行脚本。

推荐工具

免责声明

  • 本脚本旨在帮助用户删除无用的网络适配器项,提升系统性能,但由于操作涉及系统注册表,用户应自行承担使用本脚本所带来的任何风险。脚本在执行过程中会修改系统设置,若操作不当,可能会对系统产生不可逆的影响。请务必先进行充分的备份,并确保在了解风险的前提下使用本脚本。作者不承担因使用本脚本所造成的任何损失。

结语

通过本脚本,您可以轻松删除多余的网络适配器,提升系统的网络管理体验,告别强迫症带来的烦恼。我们建议在执行任何操作之前先进行适当的备份,并按照提示操作,以确保安全。

Write-Host "大哥,管理员权限运行哦,不用担心,会备份注册表,本人不负责任"
Write-Host "开始备份注册表:Network 字段"
$NetworkPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"
$backupFilePath = [System.IO.Path]::Combine([Environment]::GetFolderPath('Desktop'), "NetworkBackup_$(Get-Date -Format "ddHHmmss").reg")
reg export $NetworkPath $backupFilePath /y # 导出指定注册表路径
Write-Host ""
Get-ChildItem -Path "Registry::$NetworkPath" | ForEach-Object {
$currentPath = $_.PSPath
$connectionPath = "$currentPath\Connection"
if (Test-Path $connectionPath) {
$properties = Get-ItemProperty -Path $connectionPath
if ($properties) {
# 根据 Name 删除符合条件的项
if ($properties.Name -match "^WLAN$|^WLAN\s\d{1,2}$|^以太网$|^以太网\s\d{1,2}$|^蓝牙网络连接$|^蓝牙网络连接\s\d{1,2}$") {
$userInput = Read-Host "要删除: $($properties.Name) 吗? (y/n, default no)"
if ($userInput -eq "y") {
Remove-Item -Path $currentPath -Recurse -Force # 删除该项
Write-Host "Deleting Name: $($properties.Name)" # 打印被删除的项名称
} else {
Write-Host "Skip Name: $($properties.Name)"
}
}
}
}
}
Write-Host ""
$registryPath = "Registry::$NetworkPath\Descriptions"
$descriptions = Get-ItemProperty -Path $registryPath # 获取所有描述项
foreach ($property in $descriptions.PSObject.Properties) {
if ($property.Name -match "Bluetooth|Wi-Fi|Ethernet") { # 匹配描述项名称
$userInput = Read-Host "要设置: $($property.Name) 的值为1吗? (y/n, default no)"
if ($userInput -eq "y") {
Set-ItemProperty -Path $registryPath -Name $property.Name -Value "1" # 设置对应项的值为 "1"
Write-Host "Updated '$($property.Name)' to '1'."
} else {
Write-Host "Skip Name: $($property.Name)"
}
}
}
Write-Host ""
Write-Host "推荐一个工具集:https://www.uwe-sieber.de/misc_tools_e.html"
Write-Host "推荐一个工具:https://www.uwe-sieber.de/files/devicecleanup.zip"
Write-Host "可以用这个工具找一下网卡,然后卸载,需要提前下载驱动哦!"
Write-Host "如果还是不行,尝试设置里面修改一下名字,比如WLAN 999然后重新运行脚本, 不行就注册表搜一下手动删注册表"
Write-Host ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment