Jump to content

Auto Identify USB drive letter (..?)


Recommended Posts


Not to be a jerk but this isn't a vLite question so you shouldn't expect any replies. If you searched in the XP unattended forum (Vista is more XML) then you should have found your answer which will be something like...

set tagfile=something.txt

for %%i in (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 if exist "%%i:\%tagfile%" set keydrv=%%i

Link to comment
Share on other sites

Hi,

Here is a .CMD file which lists all of your drives and lists their types. USB Drives appear as a "Removable Drive".

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set Drive_Count=0
set DrivesList=

for /f "skip=1 TOKENS=1*" %%i in ('fsutil fsinfo drives^|more') do (
set Drive=%%i
set /a Drive_Count+=1

for /F "tokens=1* delims=- " %%A in ('fsutil fsinfo drivetype !Drive!^|find "-"') do (
echo Drive !Drive_Count!: [!Drive:~0,1! ] %%B
set MountPoint_Count=
for /F "tokens=* delims=:" %%Z in ('Mountvol^|find "!Drive:~0,1!:\"') do (
set MountPoint=%%Z
if !MountPoint:~8! NEQ !Drive! (
set /a Drive_Count+=1
set /a MountPoint_Count+=1
echo MountPoint !Drive_Count!: [!MountPoint:~8,1!!MountPoint_Count!] !MountPoint:~8!
set MountPoint[!Drive:~0,1!]=MountPoint_Count
)
)
set Drive[!Drive:~0,1!]=%%B !MountPoint_Count!
set DrivesList=!DrivesList! !Drive:~0,1!!MountPoint_Count!
)
)
rem echo Drive[q] [%Drive[q]%]
echo dl: %DrivesList%
echo off
endlocal

This code could serve as the basis of what you might be looking for.

Regards

Simon

Link to comment
Share on other sites

GTOOOOOH, please tell me your method. That may be useful for me. :sneaky:

This should get you started.

$drive = DriveGetDrive( "all" )
If NOT @error Then
For $i = 1 to $drive[0]
If $drive[$i] = "a:" Or $drive[$i] = "b:" Or $drive[$i] = "c:" Then ContinueLoop
If FileExists($drive[$i] & "\boot\boot.sdi") Then
MsgBox(0,"",$drive[$i])
Exit
EndIf
Next
EndIf

MsgBox(0,"","No drives found containing ..\boot\boot.sdi")
Exit

Link to comment
Share on other sites

Here's a variant of GTOOOOOH's script culled from the AutoIt forums that I have been using for a long time to run applications from my flash key:

$usb = DriveGetDrive("REMOVABLE")
If Not @error Then
;MsgBox(4096, "", "Found " & $usb[0] & " drives");‹-- uncomment to verify/identify all available drives
For $i = 1 To $usb[0]
If DriveGetLabel($usb[$i]) = "COR_8GB" Then
Global $MyKey = $usb[$i];‹== set flash key drive letter assignment
EndIf
Next
EndIf

The main difference is that instead of searching for a file on the key, the script searches for the key itself . . . by name. I named my key "COR_8GB." The drive letter assignment is the variable $MyKey, which can be used to run apps, like so:

RunWait( $MyKey & '\myapps\nero6\install.exe')

On a related note, here's a variant that I use to fire up WPI from a flash key named, of all things, "WPI:"

$usb = DriveGetDrive("REMOVABLE")
If Not @error Then
For $i = 1 To $usb[0]
If DriveGetLabel($usb[$i]) = "WPI" Then
$MyKey = $usb[$i]
RegWrite("HKEY_CURRENT_USER\Software\WPI", "ConfigFile", "REG_SZ", $drv & "/WPI/WPIScripts/config.js")
RegWrite("HKEY_CURRENT_USER\Software\WPI", "OptionsFile", "REG_SZ", $drv & "/WPI/WPIScripts/useroptions.js")
RegWrite("HKEY_CURRENT_USER\Software\WPI", "LogPath", "REG_SZ", $drv & "/WPI/INSTALL_LOG.txt")
Run("mshta " & $MyKey & "\WPI\WPI.hta """)
EndIf
Next
EndIf

With a custom autorun.inf file, I can just plug in the drive, click OK, and run WPI. Works well.

Edited by blinkdt
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...