Author Topic: Best way to determine if a removable disk is present in drive.  (Read 1234 times)

snowsnowsnow

  • Full Member
  • ***
  • Posts: 233
I have a USB card reader attached to my system, as drive Q:.  So, the WB function:

DiskExist("Q:")

return TRUE (1) regardless of whether or not there is an actual memory card inserted.

My goal is to be able to tell whether or not a memory card is inserted.  Most other functions that I've tried (such as DirExist()) cause a low-level error box to pop up, saying that the disk is not in the drive and giving my options "Cancel", "Try Again", and "Continue" (all of which seem to be equivalent in meaning).  Obviously, I don't want that box to come up.  And I believe that the normal error trapping routine can't stop this box from coming up.

However, I have found that using DiskVolInfo() in combination with an error trap, does work.

That is, I do:

IF udsTry(`DiskVolInfo("Q:",1)`,0,0) == "0" THEN goto No_Disk_In_Drive

udsTry is a function that sets up an IC(73) error trap and returns 0 if the evaluation of the passed in statement fails.

So, to be clear, this works, but I'm wondering if there isn't a better way.  I seem to remember doing this a long time ago, and it seemed like one of the other functions did this directly (without requiring an error trap).  Can anyone help me out on this?

Again, just to summarize, I remember having dealt with this in the past, and I have a vague memory of their being some direct function (like DriveReady() or something like that) that does it.  But I can't recall it now...

td

  • Tech Support
  • *****
  • Posts: 2223
    • WinBatch
Re: Best way to determine if a removable disk is present in drive.
« Reply #1 on: April 03, 2017, 12:58:46 pm »
The message box you referred to is brought to by your friendly local operating system, of course.  It is not a WinBatch message box or dialog. 

You may be thinking of the xDriveReady function which is provided by the Wilx extender.  The help file states that it's purpose is to "Checks whether the drive is ready indicating that there is a disk in the drive."
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


snowsnowsnow

  • Full Member
  • ***
  • Posts: 233
Re: Best way to determine if a removable disk is present in drive.
« Reply #2 on: April 03, 2017, 02:38:01 pm »
The message box you referred to is brought to by your friendly local operating system, of course.  It is not a WinBatch message box or dialog.
Yep.  That's why I referred to it as "low level" - I was pretty sure it was coming from the OS (or something similarly beyond WB's control).

Interesting, though, that DiskVolInfo() doesn't seem to cause it to be invoked.

Quote
You may be thinking of the xDriveReady function which is provided by the Wilx extender.  The help file states that it's purpose is to "Checks whether the drive is ready indicating that there is a disk in the drive."

I think we have a winner!  Now that you mention it, I'm pretty sure that's the one I used to use.
Thanks for refreshing my memory.

FWIW, I'll probably continue to use the method I am using (with DiskVolInfo()) - at least until I have occasion to do a serious overhaul of the code.

td

  • Tech Support
  • *****
  • Posts: 2223
    • WinBatch
Re: Best way to determine if a removable disk is present in drive.
« Reply #3 on: April 04, 2017, 06:51:42 am »

Yep.  That's why I referred to it as "low level" - I was pretty sure it was coming from the OS (or something similarly beyond WB's control).

Interesting, though, that DiskVolInfo() doesn't seem to cause it to be invoked.

The function does display the message for optical and floppy drives or at least it should according to MSFT.  If it does not for other devices, you will have to ask MSFT why. 

There is a way to suppress the message box in a WIL script using a couple of DllCalls. 

Quote
I think we have a winner!  Now that you mention it, I'm pretty sure that's the one I used to use.
Thanks for refreshing my memory.

I have never tried xDriveReady on a device other than an optical or floppy drive.

Quote
FWIW, I'll probably continue to use the method I am using (with DiskVolInfo()) - at least until I have occasion to do a serious overhaul of the code.

You asked.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


snowsnowsnow

  • Full Member
  • ***
  • Posts: 233
Re: Best way to determine if a removable disk is present in drive.
« Reply #4 on: April 04, 2017, 08:01:20 am »

Yep.  That's why I referred to it as "low level" - I was pretty sure it was coming from the OS (or something similarly beyond WB's control).

Interesting, though, that DiskVolInfo() doesn't seem to cause it to be invoked.

The function does display the message for optical and floppy drives or at least it should according to MSFT.  If it does not for other devices, you will have to ask MSFT why. 
Interesting.  I guess I'll have to take it up with them.

Quote
There is a way to suppress the message box in a WIL script using a couple of DllCalls. 
Very interesting.  Care to share?

Quote
Quote
I think we have a winner!  Now that you mention it, I'm pretty sure that's the one I used to use.
Thanks for refreshing my memory.

I have never tried xDriveReady on a device other than an optical or floppy drive.
You still have floppy drives???

Quote
Quote
FWIW, I'll probably continue to use the method I am using (with DiskVolInfo()) - at least until I have occasion to do a serious overhaul of the code.

You asked.
Indeed I did.  And I am grateful for your responses.  I'm sure that using xDriveReady() is the best way to do it.  I'm just being lazy in not wanting to change my code...

td

  • Tech Support
  • *****
  • Posts: 2223
    • WinBatch
Re: Best way to determine if a removable disk is present in drive.
« Reply #5 on: April 04, 2017, 01:43:19 pm »
Yes, I do still have a system with a floppy drive.  It's in my garage at the moment.

I don't have a system that will reproduce your error without some fiddling handy right now but here is how you might prevent the system message box from popping up:
Code: Winbatch
; Untested
;  DllLoad intentionally not used...
SEM_FAILCRITICALERRORS = 1
nMode = DllCall('kernel32.dll',long:'SetErrorMode', long:SEM_FAILCRITICALERRORS)
; Do something to cause the sytem error here.
DllCall('kernel32.dll', long:'SetErrorMode', long:nMode)
 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


snowsnowsnow

  • Full Member
  • ***
  • Posts: 233
Re: Best way to determine if a removable disk is present in drive.
« Reply #6 on: April 04, 2017, 04:22:36 pm »
1) I actually have a game that is on a 5.25" floppy.  I have no machine to read it on, nor any idea how to get one.  So, I envy you having such a machine in your garage.

2) That code looks interesting.  I'll let you know how it works out when I get a chance to test it.  Just out of curiosity, why does it say "DllLoad intentionally not used"?  For technical reasons or do you just not like DllLoad?  If technical, please share...

td

  • Tech Support
  • *****
  • Posts: 2223
    • WinBatch
Re: Best way to determine if a removable disk is present in drive.
« Reply #7 on: April 05, 2017, 07:50:26 am »
The reference to "DllLoad" was made in another failed attempt at humor.  It is an allusion to a rant posted by a "certain" member of the old webboard and current forum many years ago.  There is no technical reason for not using "DllLoad" that I can think of in this instance.  In the case of a just two "DllCalls" to one DLL, using it or not using it is likely a wash.  Although not using it saves some typing.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


snowsnowsnow

  • Full Member
  • ***
  • Posts: 233
Re: Best way to determine if a removable disk is present in drive.
« Reply #8 on: April 06, 2017, 11:53:53 pm »
Would that certain user be yours truly?

td

  • Tech Support
  • *****
  • Posts: 2223
    • WinBatch
Re: Best way to determine if a removable disk is present in drive.
« Reply #9 on: April 07, 2017, 06:40:18 am »
That is how I remember it but the attribution could be a false memory.  The rant was made more than ten yeas ago.  I remember the rant because it serves as a reminder to not get sloppy when posting examples on the forum to this day.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


ChuckC

  • Full Member
  • ***
  • Posts: 117
Re: Best way to determine if a removable disk is present in drive.
« Reply #10 on: April 07, 2017, 09:01:56 am »
lol... uh... i think that's what we call an epic rant... one where the knob was turned all the way up to 11.

kyle6

  • Newbie
  • *
  • Posts: 1
Re: Best way to determine if a removable disk is present in drive.
« Reply #11 on: September 11, 2017, 01:23:24 am »
Using xDriveReady() is the best way to do it
Spanish to English translator, bullet force multiplayer