MSFN Forum: Auto Identify USB drive letter (..?) - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Auto Identify USB drive letter (..?) Rate Topic: -----

#1 User is offline   kingprageeth 

  • Newbie
  • Group: Members
  • Posts: 20
  • Joined: 21-August 07

  Posted 12 September 2007 - 09:09 PM

I am writing bat files. I want my program to identify the letter of the USB flash drive which connected to the machine. Does anybody know how to do that? :sneaky:


#2 User is offline   kingprageeth 

  • Newbie
  • Group: Members
  • Posts: 20
  • Joined: 21-August 07

  Posted 19 September 2007 - 12:01 AM

Ooooh friends......, atleast tel me a way to identify the letters of all the drive partitions (with usb drive) in my machine. :wacko:

#3 User is offline   jamieo 

  • Junior
  • Pip
  • Group: Members
  • Posts: 95
  • Joined: 17-October 04

Posted 19 September 2007 - 11:33 AM

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

#4 User is offline   kingprageeth 

  • Newbie
  • Group: Members
  • Posts: 20
  • Joined: 21-August 07

Posted 24 September 2007 - 04:21 AM

:angry: :angry: :angry: -_-

This post has been edited by kingprageeth: 24 September 2007 - 04:23 AM


#5 User is offline   kingprageeth 

  • Newbie
  • Group: Members
  • Posts: 20
  • Joined: 21-August 07

Posted 24 September 2007 - 04:22 AM

No any useful ideas? :sneaky:

#6 User is online   Kelsenellenelvian 

  • WPI Guru
  • Group: Developers
  • Posts: 7,756
  • Joined: 18-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 24 September 2007 - 04:46 AM

Moving to unnatended forum.

Also isn't the USB drive letter commonly the first available free drive letter? :P

#7 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,249
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 24 September 2007 - 07:28 AM

Are you running the BAT/CMD file from the USB drive so you need to know the letter the BAT is on?

#8 User is offline   GTOOOOOH 

  • Junior
  • Pip
  • Group: Members
  • Posts: 57
  • Joined: 21-February 06

Posted 24 September 2007 - 12:12 PM

I do this now with AutoIT. Does the drive have a specific file/folder structure on it? If so, this is REALLY easy, and I can write you the code (as I've already written it for my own USB key(s)).

#9 User is offline   kingprageeth 

  • Newbie
  • Group: Members
  • Posts: 20
  • Joined: 21-August 07

Posted 25 September 2007 - 04:55 AM

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

#10 User is offline   PsiMoon314 

  • Junior
  • Pip
  • Group: Members
  • Posts: 73
  • Joined: 09-February 04

  Posted 25 September 2007 - 01:35 PM

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

#11 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,249
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 25 September 2007 - 01:38 PM

Quote

USB Drives appear as a "Removable Drive".


Actually this depends upon the drive. Most thumb drives will be removable, external hard drives are not normally.

#12 User is offline   GTOOOOOH 

  • Junior
  • Pip
  • Group: Members
  • Posts: 57
  • Joined: 21-February 06

Posted 28 September 2007 - 02:16 PM

View Postkingprageeth, on Sep 25 2007, 06:55 AM, said:

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


#13 User is offline   blinkdt 

  • Somewhat Knowledgeable
  • PipPipPipPip
  • Group: Members
  • Posts: 582
  • Joined: 30-September 03
  • OS:Vista Ultimate x64
  • Country: Country Flag

Posted 29 September 2007 - 12:23 AM

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.

This post has been edited by blinkdt: 29 September 2007 - 12:34 AM


#14 User is offline   kingprageeth 

  • Newbie
  • Group: Members
  • Posts: 20
  • Joined: 21-August 07

Posted 02 October 2007 - 11:14 PM

Thanx everybody for helping me.(Specially to GTOOOOOH,blinkdt and PsiMoon314) :hello:

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy