我有一个 bat 文件,可以显示我之前加入过的所有网络并输入过密码。但是我自己的家庭网络,bat 文件不显示我的密码的最后一个符号,即感叹号“!”抱歉,我对这类东西不太熟悉。这是我的代码:
:main
title WiFi Password Reveal v1.0
echo.
echo Reveal all saved WiFi passwords Batch file script v1.0 echo.
echo
echo.
:: Get all the profiles
call :get-profiles r
:: For each profile, try to get the password
:main-next-profile
for /f "tokens=1* delims=," %%a in ("%r%") do (
call :get-profile-key "%%a" key
if "!key!" NEQ "" (
echo WiFi: [%%a] Password: [!key!]
)
set r=%%b
)
if "%r%" NEQ "" goto main-next-profile
echo.
pause
goto :eof
:: Get the WiFi key of a given profile
:get-profile-key <1=profile-name> <2=out-profile-key>
setlocal
set result=
FOR /F "usebackq tokens=2 delims=:" %%a in (
`netsh wlan show profile name^="%~1" key^=clear ^| findstr /C:"Key Content"`) DO (
set result=%%a
set result=!result:~1!
)
(
endlocal
set %2=%result%
)
goto :eof
:: Get all network profiles (comma separated) into the result result-variable
:get-profiles <1=result-variable>
setlocal
set result=
FOR /F "usebackq tokens=2 delims=:" %%a in (
`netsh wlan show profiles ^| findstr /C:"All User Profile"`) DO (
set val=%%a
set val=!val:~1!
set result=%!val!,!result!
)
(
endlocal
set %1=%result:~0,-1%
)
goto :eof
答案1
@echo off
for /f useback^tokens^=1*delims^=: %%i in =;(`
netsh wlan show profiles ^| findstr " : "
`);= do set "_n=%%~j" & call %:^) "%%_n:~1%%"
%:^)
if not "%~1" == "" =;(
for /f usebackq^tokens^=1*^delims^=: %%i in =;(`
netsh wlan show profile name^="%~1" key^=clear ^| find "Key Content"
`);= do <nul set /p "'=WiFi: [%~1] Password: [%%~j]" );= & echo/ & exit /b
timeout -1 | echo/
你的这个代码有点令人困惑(我的看法),我建议不要修复它,而是将其重塑为可以简化事情的东西。
一个循环获取网络名称,第二个循环获取密钥并将其列在屏幕上。