I used this command to get connected WiFi password:
netsh wlan show profile name="my profile name" key=clear
but it doesn't show security key, it says:
key content = absent
Is there still any way to get it? why is it absent?
From Help
netsh wlan show profile /?
If key is set to "clear" and the caller is local administrator,
the key will be shown in plain text.
You can use this batch file to get all of the ssid's and passwords from your system. Copy and paste the code below into notepad and save it as get_ssid_pwd.cmd and then open cmd as administrator, cd to the directory where you save the file and run it as get_ssid_pwd.cmd:
#echo off
setlocal enabledelayedexpansion
for /f "tokens=2delims=:" %%a in ('netsh wlan show profile ^|find /i "All User Profile"') do (
set "ssid=%%~a"
call :getpwd %%ssid:~1%%
)
:getpwd
for /f "tokens=2delims=:" %%i in ('netsh wlan show profile name^="%*" key^=clear ^| findstr /C:"Key Content"') do echo ssid: %* pass: %%i
Related
I want to download the content to USB disk named distinguishingly in the background. So I need to find its position. Is there have any function to realize it by using a Windows command?
Or is there any function to find a USB drive by using Node.js/Electron?
And if it possible, how can I distinguish between two USB drives that have the same name?
It is possible to use %~d0 to reference the drive of the batch file if the batch file is stored on the storage media connected via USB to the computer.
But if the batch file is stored on a different storage media like the local hard disk inside the PC, the following small batch files demonstrates how to get the drive letter of the USB storage media via its volume name.
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "DriveUSB="
set "VolumeName=NameOfVolume"
:GetDriveLetter
for /F "tokens=2 delims==" %%I in ('%SystemRoot%\System32\wbem\wmic.exe LOGICALDISK where VolumeName^="%VolumeName%" GET DeviceID /VALUE 2^>nul') do set "DriveUSB=%%I"
if not defined DriveUSB (
echo Device with name %VolumeName% not found.
echo/
%SystemRoot%\System32\choice.exe /C YN /N /M "Retry (Y/N):"
if errorlevel 2 goto :EOF
goto GetDriveLetter
)
echo Drive letter of %VolumeName% is: %DriveUSB%
rem More commands using environment variable DriveUSB.
echo/
pause
endlocal
NameOfVolume must be adapted to real volume name. This string is interpreted case-insensitive by WMIC.
Please read the Microsoft documentation for Win32_LogicalDisk class and its properties for more information about the used class.
The device identification could be done also by using VolumeSerialNumber instead of VolumeName which is more difficult to change than the volume name without formatting the volume. Run in a command prompt window the following command to get displayed the volume serial number:
wmic LOGICALDISK where VolumeName="NameOfVolume" GET VolumeSerialNumber
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
choice /?
echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
rem /?
setlocal /?
wmic /?
wmic logicaldisk /?
wmic logicaldisk get /?
Read the Microsoft documentation about Using command redirection operators for an explanation of 2>nul. The redirection operator > must be escaped with caret character ^ on FOR command line to be interpreted as literal character when Windows command interpreter processes this command line before executing command FOR which executes the embedded wmic command line with using a separate command process started in background with %ComSpec% /c and the command line within ' appended as additional arguments. This is also the reason why = must be escaped with ^ to be interpreted as literal character and not as argument separator which would be replaced otherwise by a space character by command processor instance processing the batch file making the where clause invalid for wmic executed by the background command process.
It is recommended to read also DosTips forum topic: ECHO. FAILS to give text or blank line - Instead use ECHO/
Based on the code below, the output of Var is (COM19). I was wandering what command can be used to remove the brackets? Tried using sed, but would ideally want a solution that doesn't not require additional installations on Windows.
#echo off
setlocal
wmic path win32_pnpentity get caption /format:list > output.txt
for /f "tokens=4" %%a in ('find /i "USB Serial Port" output.txt') do set var=%%a
pause
goto :EOF
for /f "delims=()" %%a in ("%output%") do (echo %%a)
Managed to solve the issue ussing the delims, in line with the token function. Code can be seen below.
#echo off
setlocal
wmic path win32_pnpentity get caption /format:list > output.txt
for /f "tokens=2 delims=()" %%a in ('find /i "USB Serial Port" output.txt') do set var=%%a
pause
Hi I'm trying to write a batch script that reads a long text file, finds a line that says:
Location: xxxxxxxx
And saves xxxxxxxx (only) as a variable that i can use later in the script.
xxxxxxxx is an ID and there is nothing else on that line.
Can someone help?
This works, too.
for /f "tokens=2" %a in ('type longtextfile.txt ^|findstr /b "Location"') do set location=%a
echo %location%
EDIT: Adding Aacini's more efficient way of doing this:
for /f "tokens=2" %a in ('findstr /b "Location" longtextfile.txt') do set location=%a
echo %location%
There are just a few standard Windows commands required for this simple task:
#echo off
set "TextFile=C:\Temp\Text file to search for location.txt"
if not exist "%TextFile%" echo Can't find file: "%TextFile%"& goto :EOF
for /F "usebackq tokens=1* delims=: " %%I in ("%TextFile%") do (
if /I "%%I" == "Location" (
set "Location=%%J"
goto FoundLocation
)
)
echo No location found in file: "%TextFile%"
goto :EOF
:FoundLocation
echo Location is: %Location%
On second line the name of the text file with path must be defined.
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
echo /?
for /?
if /?
goto /?
set /?
I have a bunch of excel files and other types of files that I need to populate into a spreadsheet to keep track of them. I was what the batch script would look like for such task. Also I want to be able to pin point which folders I want to get the file names from.
Thanks in advance
Dir does do multiple folders.
dir c:\windows "c:\program files\e*.txt" /a
Here's doing My Docs.
for /f "skip=2 tokens=3" %A in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Personal"') do set doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "\/"^|findstr /l /v "Pictures Music Video"`) DO #echo %j&echo.
Like the title says, I would like to know how to search a specified directory for a specified file using a for loop in a windows batch script. I can't use any 3rd party software.
Heres what I have at the moment:
for /R "%loc%" %%f in ("%searchterm%") do (
echo %%f
echo %%f>> "%genloc%wefound.txt"
)
%loc% is the location in which it should search.
%searchterm% is the file (e.g "hello.txt") that the script much search for.
It must output any files found (including their full path) on the screen and into the wefound.txt.
Let me know if you need more detail.
for /f "delims=" %%f in ('dir /s /b /a-d "%loc%\%searchterm%"') do (
echo %%f
echo %%f>> "%genloc%wefound.txt"
)
To get the for /r command recursively enumerate the files under a starting point, the file set must include some wildcard character (* or ?). As you know the exact filename, let the dir command do the work of searching the file.
for /R "%loc%" %%f in ("%searchterm%") do (
echo %%~Ff
echo %%~Ff>> "%genloc%wefound.txt"
)
For further details, type: FOR /?
Why complicate things with FOR? All you need is the DIR command:
dir /s /b /a-d "%loc%\%searchterm%>"%genloc%wefound.txt"&type "%genloc%wefound.txt"
The solution is even better if you can get your hands on a Windows port of the tee command (there are numerous free versions available). You could use my hybrid JScript/batch implementation of tee
dir /s /b /a-d "%loc%\%searchterm%"|tee "%genloc%wefound.txt"