Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: USB Drive Letter Finder Script  (Read 17213 times)

0 Members and 1 Guest are viewing this topic.

googleknowsbest

    Topic Starter


    Starter

  • "Winning"
    • Yes
  • Experience: Familiar
  • OS: Windows XP
USB Drive Letter Finder Script
« on: April 02, 2013, 11:32:32 AM »
This is my first post so cut me some slack.

To start out, this script CANNOT use vbasic scripts or the wmic command.
It needs to be done in CMD prompt.



I have a USB Rubber Ducky (USB programmable HID/Mass storage device) and I need to run a command to find the drive letter of the device named 'DUCKY' mounted. And set the drive letter as a variable. So I can run or open other files on the device.


I found out, some bare windows installs CANNOT run this command to find the device 'DUCKY'
Code: [Select]
for /f %d in ('wmic volume get driveletter^, label ^| findstr "DUCKY"') do set myd=%d
Here's the output:
Code: [Select]
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\X>for /f %d in ('wmic volume get driveletter^, label
 ^| findstr "DUCKY"') do set myd=%d
'wmic' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\X>

I need this command to be short and compatible with most old and new Windows OS.
So I tried to venture this quest on my own.

Here's my progress:
Code: [Select]
echo list volume | diskpart | findstr "DUCKY"
Output:
Code: [Select]
C:\Documents and Settings\X>echo list volume | diskpart | findstr "DUCKY"
  Volume 2     F   DUCKY        FAT    Removeable   239 MB

C:\Documents and Settings\X>


Now all I need to do is extract the Drive letter (witch changes from system to system) into a variable. THATS IT.

Ive searched weeks for this answer and never found it solved by using the basic command prompt. I made lots of progress but at this point my skill are at its limit.

Please help me find the answer!
« Last Edit: April 02, 2013, 12:31:10 PM by googleknowsbest »
"A person who never made a mistake never tried anything new." -Albert Einstein

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: USB Finder Script... HELP
« Reply #1 on: April 02, 2013, 11:51:54 AM »
try
Code: [Select]
for /f "tokens=3 delims= " %A in ('echo list volume ^| diskpart ^| findstr "DUCKY"') do (
set DUCKYdrive=%A
)

double % if you are using it in a batch file.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

googleknowsbest

    Topic Starter


    Starter

  • "Winning"
    • Yes
  • Experience: Familiar
  • OS: Windows XP
Re: USB Finder Script... HELP
« Reply #2 on: April 02, 2013, 11:56:23 AM »
Thank you so much! :o ;D ;D

 Also how did you lean all that? My expertise is in Linux.
"A person who never made a mistake never tried anything new." -Albert Einstein

Lemonilla



    Apprentice

  • "Too sweet"
  • Thanked: 70
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: USB Finder Script... HELP
« Reply #3 on: April 02, 2013, 11:57:45 AM »
Practice, patience, and a lot of extra time.
Quote from: patio
God Bless the DOS Helpers...
Quote
If it compiles, send the files.

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: USB Finder Script... HELP
« Reply #4 on: April 02, 2013, 02:27:49 PM »
Thank you so much! :o ;D ;D

 Also how did you lean all that? My expertise is in Linux.
Same way you probably learned shell scripting in linux.

patio

  • Moderator


  • Genius
  • Maud' Dib
  • Thanked: 1769
    • Yes
  • Experience: Beginner
  • OS: Windows 7
Re: USB Drive Letter Finder Script
« Reply #5 on: April 02, 2013, 02:47:11 PM »
I removed the Poll because it's silly to ask what the quality of your 1st Post is.

That being said Welcome to Computer Hope.
" Anyone who goes to a psychiatrist should have his head examined. "

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: USB Drive Letter Finder Script
« Reply #6 on: April 02, 2013, 04:17:14 PM »

Code: [Select]
@echo off
for %%a in (d e f g h i j k l m n o p q r s t u v w x y z) do vol %%a: 2>nul |find "DUCKY" >nul && set drv=%%a:
echo. %drv%