WiFi密码记不住?Excel这个骚操作,把你连过的所有密码全扒出来!
大家有没有这种尴尬——朋友来家里玩,一屁股坐下就问:“WiFi密码多少啊?”你脑子一片空白,只记得是字母数字混合,具体是啥?早忘了!只能撅着屁股趴地上,对着路由器背面那串芝麻大的字,眯着眼睛看半天……
其实,你的Windows电脑就像个学霸,你连过的每一个WiFi,它都偷偷记在小本本上了!今天教你用Excel里的一段VBA代码,把这个小本本翻出来,WiFi名和密码整整齐齐列出来,像成绩单一样!
代码逻辑?简单得很,就像老师查作业:
- 1. 老师点名:代码让电脑执行“netsh wlan show profiles”,把你连过的所有WiFi名字(比如“CMCC-5G”)列个清单。
- 2. 翻成绩单:挨个问系统:“这个WiFi密码是多少?”加上暗号“key=clear”,系统就乖乖交出明文密码。
- 3. 抄作业:把名字和密码填到Excel的A列和B列,完事儿还自动调整列宽,让你看得清清楚楚!
别磨叽,代码直接复制粘贴就能用!
Option Explicit' 主函数:获取所有保存的WiFi配置文件及其密码Sub GetAllWiFiPasswords() Dim strProfiles As String Dim arrProfiles() As String Dim i As Long Dim profileName As String Dim wifiPassword As String Dim outputRow As Long ' 设置输出起始位置(A1为WiFi名称,B1为密码) outputRow = 1 Cells(outputRow, 1).Value = "WiFi名称 (SSID)" Cells(outputRow, 2).Value = "密码" Cells(outputRow, 1).Font.Bold = True Cells(outputRow, 2).Font.Bold = True outputRow = outputRow + 1 ' 1. 获取所有保存的WiFi配置文件名称 strProfiles = RunCommand("netsh wlan show profiles") ' 从输出中提取所有WiFi名称 arrProfiles = ExtractWiFiNames(strProfiles) ' 2. 遍历每个WiFi名称,查询其详细信息以获取密码 If UBound(arrProfiles) >= 0 Then For i = 0 To UBound(arrProfiles) profileName = arrProfiles(i) wifiPassword = GetPasswordForProfile(profileName) ' 输出到工作表 Cells(outputRow, 1).Value = profileName Cells(outputRow, 2).Value = wifiPassword outputRow = outputRow + 1 Next i ' 自动调整列宽 Columns("A:B").AutoFit MsgBox "共找到 " & (outputRow - 2) & " 个WiFi配置。", vbInformation Else MsgBox "未找到保存的WiFi配置文件。", vbExclamation End IfEnd Sub' 辅助函数:执行Shell命令并返回文本结果Private Function RunCommand(cmd As String) As String Dim objShell As Object Dim objExec As Object Dim strOutput As String Set objShell = CreateObject("WScript.Shell") Set objExec = objShell.Exec("cmd /c " & cmd) strOutput = objExec.StdOut.ReadAll RunCommand = strOutputEnd Function' 辅助函数:从“netsh wlan show profiles”的输出中提取所有WiFi名称Private Function ExtractWiFiNames(profileOutput As String) As String() Dim lines() As String Dim i As Long Dim names() As String Dim nameCount As Long Dim line As String Dim startPos As Long ReDim names(0 To 0) As String nameCount = 0 lines = Split(profileOutput, vbCrLf) For i = 0 To UBound(lines) line = Trim(lines(i)) If InStr(line, "所有用户配置文件") > 0 Or InStr(line, "All User Profile") > 0 Then startPos = InStr(line, ":") If startPos > 0 Then If nameCount > 0 Then ReDim Preserve names(0 To nameCount) As String names(nameCount) = Trim(Mid(line, startPos + 1)) nameCount = nameCount + 1 End If End If Next i If nameCount = 0 Then ReDim names(-1 To -1) As String ExtractWiFiNames = namesEnd Function' 辅助函数:查询指定WiFi配置文件的密码Private Function GetPasswordForProfile(profileName As String) As String Dim detailedInfo As String Dim lines() As String Dim i As Long Dim line As String Dim pwd As String pwd = "<需要管理员权限>" detailedInfo = RunCommand("netsh wlan show profile name=""" & profileName & """ key=clear") lines = Split(detailedInfo, vbCrLf) For i = 0 To UBound(lines) line = Trim(lines(i)) If InStr(line, "关键内容") > 0 Or InStr(line, "Key Content") > 0 Then Dim startPos As Long startPos = InStr(line, ":") If startPos > 0 Then pwd = Trim(Mid(line, startPos + 1)) Exit For End If End If Next i GetPasswordForProfile = pwdEnd Function
注意:最好用管理员身份运行Excel,不然系统可能不给面子,密码栏只显示“需要管理员权限”。但WiFi名字肯定能出来,赶紧试试吧!
#VBA #EXCEL技巧 #WiFi密码
📢 重要通知:不想错过「Excel每日一学」的每一篇干货? 由于公众号推送规则调整,“设为星标” 是确保您能准时收到我们原创内容的最佳方式。
✨ 请您花2秒完成:
点击顶部公众号名称,进入主页。
点击右上角 【…】,选择 【设为星标】。
您的👍 点赞 +
转发 +
在看,是对我们持续分享的最大支持!
感谢您阅读至此。
为保障账号持续运营与内容创作,文中或文末可能会穿插由平台智能推荐的内容,仅供参考,您可根据自身需求自由选择。我们的核心始终不变:与您一起,每天进步一点!💪
📂 获取示例文件 留言并后在台发送“260223”即可领取,直接拿去用!,即可获取配套示例文件 (含代码)