I need usb scanner!?! batch

February 21, 2009 at 05:51:03
Specs: Windows XP
My xp is 'modified' and it is hard to find
external usb drives when they are connected.
Main thing of this is only batch files and
some type of exes is working in my xp. SO
i've been figuring out how to make batch file
which can check is my usb drive: 3532, 3953 or 6235 connected on usb. thx from advice

See More: I need usb scanner!?! batch

Report •

February 21, 2009 at 06:45:26
What do you mean by 3532, 3953 or 6235?

I have a batch that scans for usb flash drives via reg.exe that gives the text string identifier i.e. "kingston data traveller 2.0 usb device". Not sure if it's what your looking for or if it will work on your "modifed" version of xp. Also not sure if it picks up usb hdds....

Of course if your not after the text strings something much simpler could do the job.

@echo off&setlocal
set hexval=""................................ !"#$.&...*+,-./0123456789:;.=.?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]._`abcdefghijklmnopqrstuvwxyz{.}~.................................................................................................................................""
echo:                   Scanning for usb flash drives.......
set dcnt=
ver|find "n 5">nul&&goto nt5
for /f "delims=" %%a in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR^|find /i "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR\"') do (
for /f "delims=" %%b in ('reg query "%%a"^|find /i "%%a\"') do (
set flshtmp="%%b"
set flshtmp=!flshtmp:%%a\=!
set /a dcnt+=1
set chk=
for /f "tokens=1,2*" %%c in ('reg query "%%b"^|find /i "FriendlyName"') do (
set fname!dcnt!="%%e"&&set /a chk+=1
set id!dcnt!=!flshtmp!
set flshtmp=
if !chk! neq 1 set /a dcnt-=1
goto merge

for /f "delims=" %%a in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR^|find /i "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR\"') do (
for /f "delims=" %%b in ('reg query "%%a"^|find /i "%%a\"') do (
set /a dcnt+=1
set chk=
for /f "tokens=1,2*" %%c in ('reg query "%%b"^|findstr /i "ParentIdPrefix FriendlyName"') do (
if /i "%%c"=="ParentIdPrefix" set id!dcnt!="%%e"&&set /a chk+=1
if /i "%%c"=="FriendlyName" set fname!dcnt!="%%e"&&set /a chk+=1
if !chk! lss 2 set /a dcnt-=1

set lcnt=
for /f "tokens=2,4 delims=\	 " %%g in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices^|find ":"') do (
set /a lcnt+=1
set drvltt!lcnt!=%%g
set drvdat!lcnt!=%%h
for /l %%i in (1,1,!lcnt!) do (
set nn=%%i
set tdat=
call :delin
goto cnvrt
if not defined drvdat%nn% set drvdat%nn%=%tdat:~1%&&goto :eof
set tdat=%tdat%¼!drvdat%nn%:~0,2!
set drvdat%nn%=!drvdat%nn%:~2!
goto delin
set hexval=!hexval:~2,-2!
set svr=!hexval!
for /l %%j in (1,1,!lcnt!) do (
set drvdat%%j=!drvdat%%j:00¼=!
set drvdat%%j=!drvdat%%j:¼00=!
set nn=%%j
set hexval=!svr!
for %%k in (0 1 2 3 4 5 6 7 8 9 a b c d e f) do (
for %%l in (0 1 2 3 4 5 6 7 8 9 a b c d e f) do (
set byte=%%k%%l
call :chge
for /l %%m in (1,1,!lcnt!) do set drvdat%%m=!drvdat%%m:¼=!
goto check
set thex=!byte!=!hexval:~0,1!
set thex="!thex:&=^&!"
set thex=!thex:~1,-1!
set drvdat%nn%=!drvdat%nn%:%thex%!
set hexval=!hexval:~1!
goto :eof

set fcnt=
for /l %%n in (1,1,!dcnt!) do (
for /l %%o in (1,1,!lcnt!) do (
echo "!drvdat%%o!"|find !id%%n!>nul
if not errorlevel 1 (
dir !drvltt%%o!\ 2>&1|>nul find /i "volume"
if not errorlevel 1 (
set /a fcnt+=1
set itmed!fcnt!=!drvltt%%o! - !fname%%n!
set srtcnt=1
for %%q in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
for /l %%r in (1,1,!fcnt!) do (
set vrcnt=%%r
call :srtr %%q
goto tchup
if /i "%1"=="!itmed%vrcnt%:~0,1!" (
set output!srtcnt!=!itmed%vrcnt%!
set /a srtcnt+=1
goto :eof

for /l %%a in (1,1,!fcnt!) do (
for /f "tokens=5,* delims= " %%b in ('vol !output%%a:~0^,2! ^|find /v /i "serial"') do (
if /i not "%%c"=="no label." set output%%a=!output%%a! - "%%c"
set /a fcnt+=1
set output!fcnt!=Rescan to detect newly connected devices.
set /a fcnt+=1
set output!fcnt!=Exit
echo: Your options are.....
if !fcnt! gtr 2 echo:     Drive letter - Device identifier - Volume label
for /l %%p in (1,1,!fcnt!) do echo: %%p. !output%%p!
set /p dest= Please select a flash drive or option:
for /l %%p in (1,1,!fcnt!) do if "%%p"=="!dest!" goto finish
echo Invalid choice - select again
goto loop
if /i "!output%dest%!"=="exit" pause&&goto :eof
if /i "!output%dest%!"=="Rescan to detect newly connected devices." endlocal&&goto begin
set dest=!output%dest%:~0,2!
endlocal&endlocal&set dest=%dest%
echo You selected drive %dest%

Sorry for the long post, would have just thrown a link to other threads where I have posted this but it has been modified since then....

By the way I'm offering no support for this because I'm about to pack my pc away and get the net disconnected indefinitely - bye everyone....

Report •

February 21, 2009 at 09:11:37
ok thanks that helped a lot!
3532, 3953, 6235 meant flash drive names
anyway this was helpful

Report •

February 21, 2009 at 22:03:44
I have updated the above script to include volume labels in xp - can't verify any other os's.

Report •

Related Solutions

Ask Question