Jump to content
Sign in to follow this  
j.gilbert

USB or Floppy?

Recommended Posts

Hi all,

I'm working on a script that utilizes a USB drive. This may be an easy answer (I hope), but all other aspects of my script work - without a floppy drive in the picture. I would like to know if anyone could help me find the way to narrow down to an exact match to pinpoint whether the script has found the USB drive. Here is my script:

; Check to see if there is a USB Storage Device Connected
$loop = 1
While $loop = 1
$var = DriveGetDrive( "REMOVABLE" )
    if @Error=1 Then
   ; Prompt to put USB drive in.
$choice = MsgBox(5,"No Drive", "Unable to find USB Drive" & @CRLF & "Please insert USB Drive and click Retry")
    if $choice = 2 Then
    Exit
    EndIf
            Else   
; Exit the loop
            $loop = 0 
    EndIf
WEnd

This works fine if a user doesn't have a floppy drive enabled. Rather than disable all the user's floppy drives, I'd like to see if I can narrow it down.

Some Ideas I have are to check for file space on each drive and if less than 1.5 megs, maybe call that the floppy and move to the next drive.

However, If the USB drive is not plugged in, I want to be able to detect that. And USB drives have various drive capacities I'd still need to be able to see if the next available drive is a REMOVABLE drive.

Here is another question: in the function DriveGetDrive("all"), is the order of the returned array of drives always going to begin with REMOVABLE drives first?

I think I'm pretty close, but would like to see if anyone has some input on this. I've also searched for +usb +floppy on the forum and didn't find anything addressing this.

Thank you in advance for your help.

Share this post


Link to post
Share on other sites

May be you can use DriveGetFileSystem() and list/search for the file system specification. I think most USB Drives use the FAT file system.

I don't have a USB drive so no way of testing...

Share this post


Link to post
Share on other sites

May be you can use DriveGetFileSystem() and list/search for the file system specification.  I think most USB Drives use the FAT file system.

I don't have a USB drive so no way of testing...

<{POST_SNAPBACK}>

Thanks for the suggestion. Unfortunately Floppy is labeled as FAT as well.

I'm getting closer with this:

$DriveFile = "c:\Temp\driveGet.ini"
FileDelete ($DriveFile)

$varAll = DriveGetDrive( "REMOVABLE" )
If NOT @error Then
        For $i = 1 to $varAll[0]
        IniWrite($DriveFile, "Drive " & $i, "DriveLetter", $varAll[$i])
    Next
EndIf

$drive1 = IniRead($DriveFile, "Drive 1", "DriveLetter", "No Drive Found.")
$drive2 = IniRead($DriveFile, "Drive 2", "DriveLetter", "No Drive Found.")

But out of time for the night to write a loop to check both drives. If anybody has any more suggestions, please post. If I get it finished first, I'll post what worked for me. I'd like to see any other ideas if anybody has any.

Thanks again.

Share this post


Link to post
Share on other sites

drive letter for floppy are A: or B:

for USB >=C: unless you redefine explicitly :(

Share this post


Link to post
Share on other sites

drive letter for floppy are A: or B:

for USB >=C: unless you redefine explicitly  :(

<{POST_SNAPBACK}>

Thanks. In my loop to come, I was addressing the a: or b: = go away thing, but I figured any other drive letter starting with e: and beyond would be fine, since usually C: is the hard drive and I'm only checking "REMOVABLE" drives. That should be fine right? or should I look for any 'REMOVABLE" drive letter past B:? I'm unable to work more on it until tonight. :(

Share this post


Link to post
Share on other sites
Guest Calimero

i had the same problem 3 weeks before

i can give you my script if you need it

it serach for an usb stick and gives out the drives or save it in a variable

pm if requiered

Share this post


Link to post
Share on other sites

One thing you have to be careful of for this script to be able to port to other computers you would need to be sure not only is it not a floppy, but what about a CD or DVD. Those wont be solved by the A: or B: thing.

Just some more kinks :(,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

i had the same problem 3 weeks before

i can give you my script if you need it

it serach for an usb stick and gives out the drives or save it in a variable

pm if requiered

<{POST_SNAPBACK}>

I'd like to see your script, Calimero. Can you post it?

I'm doing a lot of work right now with scripts running from my usb drive. I might, someday, need something like this.

BTW, how do you determine the difference between:

<E:> Removable media <-- Digicam memory card

and

<F:> Removable media <-- usb drive

Share this post


Link to post
Share on other sites
Guest darthdurden

starting with e: and beyond would be fine, since usually C: is the hard drive and I'm only checking "REMOVABLE" drives.

SATA hard drives can be set up so that they are hot swappable... so you can actually have ur main C: hard drive be a removable drive... winxp will detect it that way if you use the actual SATA power connector and not a regular molex 4-pin... thats how my compy is set up...

so i have that little removable hardware thing in the corner in winxp... so you have to watch for that too

and this is off topic... anyone know what would happen if i went through the actions to "stop" that drive and disconnect it? i assume that windows won't allow you to do that... but i haven't dared try

DD

Share this post


Link to post
Share on other sites

Maybe this helps:

#include <string.au3>
$usb = DriveGetDrive( "REMOVABLE" )
If NOT @error Then
     For $i = 1 to $usb[0]
$usbdev = RegRead("HKLM\SYSTEM\MountedDevices", "\DosDevices\" & $usb[$i])
$usbrealdev = _HexToString($usbdev)
    If StringInStr ( $usbrealdev, "STORAGE#RemovableMedia#" ) then
     If DriveGetFileSystem ( $usb[$i] ) <> "NTFS" then MsgBox(0,"USB-Drive", $usb[$i])
    Endif
    Next
Endif
:( Edited by Westi

Share this post


Link to post
Share on other sites

I was afraid of "REMOVABLE" being too general of a thing to narrow to a USB drive for all the reasons I thought, AND all the reasons you all listed above. I know that when a USB drive is in by itself, the array value is [1], and when a floppy drive is enabled, the floppy becomes [1] and USB drive is [2]. But I haven't tried it with any other "REMOVABLE" drive plugged in, in addition to these two. So all of your points are well taken and I appreciate the responses.

I'm going to see if I can make an exact match everytime tonight, starting with Westi's suggestion. Also, if I can't match it that way, I may try some type of flag file that will help me identify I have found the "Correct" removable drive.

I feel it can be done, and when I get it completed, I'll post for others to see.

Thanks again for all of your input. It's helping. :(

Share this post


Link to post
Share on other sites

SATA hard drives can be set up so that they are hot swappable... so you can actually have ur main C: hard drive be a removable drive...  winxp will detect it that way if you use the actual SATA power connector and not a regular molex 4-pin... thats how my compy is set up...

so i have that little removable hardware thing in the corner in winxp... so you have to watch for that too

and this is off topic... anyone know what would happen if i went through the actions to "stop" that drive and disconnect it? i assume that windows won't allow you to do that... but i haven't dared try

DD

<{POST_SNAPBACK}>

Good point. I don't have a SATA drive hooked up yet, but maybe I should then further qualify it to DriveGetDrive("REMOVABLE") AND DriveGetFileSystem to accept only Removable FAT systems. I know this wouldn't reduce it to 0% error, but it would help narrow further.

As for the stopping your SATA from within WinXP, it makes me want to go get a SATA drive and try it. I'm assuming it wouldn't either, but...

Share this post


Link to post
Share on other sites

In my system, the code didn't do anything. I had to modify it so that it read:

#include <string.au3>
$usb = DriveGetDrive( "REMOVABLE" )
If NOT @error Then
     For $i = 1 to $usb[0]
$usbdev = RegRead("HKLM\SYSTEM\MountedDevices", "\DosDevices\" & $usb[$i])
$usbrealdev = _HexToString(StringReplace($usbdev,"00",""))
    If StringInStr ( $usbrealdev, "STORAGE#RemovableMedia#" ) then
     If DriveGetFileSystem ( $usb[$i] ) <> "NTFS" then MsgBox(0,"USB-Drive", $usb[$i])
    Endif
    Next
Endif
Edited by Dougiefresh

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...