Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

USB stick, FINDSTR

Hi guys,

I've not really used FINDSTR before, I did have an example of it's usage which I could have copied over but I can't find it... 😭

the SS64 page is confusing me so I've come here;
I'd like to be able to show a list of drives on the computer AND the name of the drive (so say if I'd named my usb stick to "goggleStick")

Given how if I put that stick into another computer, it's drive letter may be different, but it's name would be the same. I'd like to be able to use some sort of find command on a list of drives, to locate it by it's name, then get the drive letter out of the list, and assign that to a variable.


Current research into displaying a drive list:
I found diskpart list volume (from here)
unfortunately it's not possible to simply type in "diskpart list volume" as diskpart must first run, and seperately have "list volume" typed in. This would interrupt a batch script whilst diskpart is running. So that's out.


WMIC is good!
I found on the same site the suggestion of
"wmic logicaldisk get deviceid, volumename, description"
to show some drive information, for some reason the output came in the order
"description, deviceid (which was the drive letter), volumename (e.g. goggleStick)"
I can cut this down to "WMIC logicaldisk get deviceid, volumename"
which gives firstly the drive letter, then the name, one per line.


then I assume somehow pipe this into a findstr command, which puts it into a variable, then use partial variables to extract the first letter, which will be the drive letter, so I can reference the usb stick's files.
"%drivelett%:/folder/file.type"


Thanks for any help! 🤗
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Hi 🤝

And what did you thing about this code ✌
it comes from this thread : [FixTool] Show all hidden folders and files on your USB pendrive by Hackoo

PHP Code

<?php 
@echo off
Mode 75
,7 & Color 9E
Title Detect automatically your USB key letter by Hackoo 2016
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=2" ^|find /i ":"') do (Set MyUSB=%%i)
cls
setlocal ENABLEDELAYEDEXPANSION
set _drive
=%MyUSB%
If 
Exist !_drive! (
cls
echo.
echo           
#########################################################
echo                        Your usb key is connected as !_drive!
echo           
#########################################################
echo.
pause
Explorer 
"!_drive!\"
) ELSE (
cls
color 0C
echo.
echo           #########################################################
echo                         Your usb key is not detected
echo           #########################################################
echo.
pause
Exit
) 

So, if this code really help you ; don't forget to rate it 😝
Cheers
(Mar 24, 2016 08:55 PM)Hackoo Wrote:  Hi 🤝

And what did you thing about this code ✌
it comes from this thread : [FixTool] Show all hidden folders and files on your USB pendrive by Hackoo

-snip-

So, if this code really help you ; don't forget to rate it 😝
Cheers

Hi Hackoo, I don't know how I would apply this to my situation? It appears this just locates the first usb stick it finds..or..something?

It's important to my little project that I can find the drive's name and from that name find it's drive letter (e.g. find a drive named "GoggleStick" and find it's drive letter, which could be "F:")

I need to do it in that order because I want the script to use a specifically named USBstick of my choice, on any computer, where the drive letter assigned to the drive may vary, due to whatever it is that windows decides on a drive letter.

(I cant currently find a usb stick that will let me name it, I think my AV is interrupting it, so for example sake I'll use my CD drive)
using
Code
MIC logicaldisk get deviceid, volumename
displays this:
[Image: NlBXyi4.png]

I'd like to pipe this output into a findstr command to search for the drive name, (e.g. "THE_WALKING_DEAD_S04", and it would find the line that contains this, and put that entire line into a variable "%founddrive%",
THIS IS WHERE I'M CLUELESS, because I don't know how to use findstr.
Unless there is more I can do with wmic, but I have even less idea there, I've been unable to find findstr in either of the pinned posts here.

Thanks again
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3
Hi 🤝
We suppose that your USB Stick Name is "goggleStick" so, this batch can return to you its driveletter, just give a try and tell me the result 👍

PHP Code

<?php 
@echo off
set USB_Stick_Name
=goggleStick
set cmd
="WMIC logicaldisk get deviceid, volumename | findstr /I "%USB_Stick_Name%""
FOR /F %%i IN ('%cmd%') DO SET USBDriveLetter=%%i
IF %ERRORLEVEL% EQU 0 Echo %USBDriveLetter% 
pause 
(Mar 26, 2016 08:29 AM)Hackoo Wrote:  Hi 🤝
We suppose that your USB Stick Name is "goggleStick" so, this batch can return to you its driveletter, just give a try and tell me the result 👍

PHP Code

<?php 
@echo off
set USB_Stick_Name
=goggleStick
set cmd
="WMIC logicaldisk get deviceid, volumename | findstr /I "%USB_Stick_Name%""
FOR /F %%i IN ('%cmd%') DO SET USBDriveLetter=%%i
IF %ERRORLEVEL% EQU 0 Echo %USBDriveLetter% 
pause 

This is excellent! Does exactly what I wanted! :) Thank you Hackoo, were I able, I'd +1 you 👍

I don't quite get how you're singling out the drive letter, is it to do with space " " being a deliminator in the FOR loop, and for each thing it adds one to errorlevel or something, so it just stops after the first bit?
However it's done, it's great, I can now make my little project :D
Keep me fed and alive at Uni: Bitcoin Bitcoin: 16cwoYXfhaK6V5c8kJKn9SBMtDUARUs7BS
I'll draw terrible art in paint.NET for you, on request, in return <3


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by zaskMar 12, 2017 10:35 AM 1 130 Mar 12, 2017 10:35 AM
Last Post: zask
[.NET] by Zilog80Feb 16, 2017 11:56 AM 12 743 Feb 16, 2017 11:56 AM
Last Post: Zilog80
[.NET] by danielpherlioMay 28, 2016 02:17 AM 3 554 May 28, 2016 02:17 AM
Last Post: Decim