WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: snowsnowsnow on April 03, 2017, 09:39:35 AM

Title: Best way to determine if a removable disk is present in drive.
Post by: snowsnowsnow on April 03, 2017, 09:39:35 AM
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...
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: td 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."
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: snowsnowsnow on April 03, 2017, 02:38:01 PM
Quote from: td 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.
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.

QuoteYou 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.
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: td on April 04, 2017, 06:51:42 AM
Quote from: snowsnowsnow on April 03, 2017, 02:38:01 PM

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.
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: snowsnowsnow on April 04, 2017, 08:01:20 AM
Quote from: td on April 04, 2017, 06:51:42 AM
Quote from: snowsnowsnow on April 03, 2017, 02:38:01 PM

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.

QuoteThere 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...
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: td 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) Select
; 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)
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: snowsnowsnow 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...
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: td 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.
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: snowsnowsnow on April 06, 2017, 11:53:53 PM
Would that certain user be yours truly?
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: td 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.
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: ChuckC 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.
Title: Re: Best way to determine if a removable disk is present in drive.
Post by: kyle6 on September 11, 2017, 01:23:24 AM
Using xDriveReady() is the best way to do it