1. [WIN] GetLogicalDrives returns drives NOT present

When I wrap the function GetLogicalDrives, it works, except that it 
returns drive numbers for drives that aren't actually there yet, exactly as
"My Computer" does, ie, usb drives that aren't currently plugged in.  And then
if I use "dir" to see if a drive is "ready", I get a non-fatal error message.

What I was trying to do was find out what drives are on the system, and then
if they were removable or not.  But I don't want to check drives that aren't
actually there.

Any suggestions??

Dan Moyer

new topic     » topic index » view message » categorize

2. Re: [WIN] GetLogicalDrives returns drives NOT present

Dan Moyer wrote:
> 
> 
> When I wrap the function GetLogicalDrives, it works, except that it 
> returns drive numbers for drives that aren't actually there yet, exactly as
> "My Computer" does, ie, usb drives that aren't currently plugged in.  And then
> if I use "dir" to see if a drive is "ready", I get a non-fatal error message.
>  
> 
> What I was trying to do was find out what drives are on the system, and then
> if they were removable or not.  But I don't want to check drives that aren't
> actually there.
> 
> Any suggestions??
 
Dan:

    Be sure that you unmount the USB drives before you remove them.

    Windows when it loads assigns the drive numbers when it boots

    and when you remove a USB drive it's drive number does not go

    away.

    You did't say what operating system you are using which may make a

    difference.

    Here is a link that might help:

    http://www.uwe-sieber.de/usbstick_e.html

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

3. Re: [WIN] GetLogicalDrives returns drives NOT present

Bernie Ryan wrote:
> 
> Dan Moyer wrote:
> > 
> > 
> > When I wrap the function GetLogicalDrives, it works, except that it 
> > returns drive numbers for drives that aren't actually there yet, exactly as
> > "My Computer" does, ie, usb drives that aren't currently plugged in.  And
> > then
> > if I use "dir" to see if a drive is "ready", I get a non-fatal error
> > message.
> >  
> > 
> > What I was trying to do was find out what drives are on the system, and then
> > if they were removable or not.  But I don't want to check drives that aren't
> > actually there.
> > 
> > Any suggestions??
>  
> Dan:
> 
>     Be sure that you unmount the USB drives before you remove them.
> 
>     Windows when it loads assigns the drive numbers when it boots
> 
>     and when you remove a USB drive it's drive number does not go
> 
>     away.
> 
>     You did't say what operating system you are using which may make a
> 
>     difference.
> 
>     Here is a link that might help:
> 
>     <a
>     href="http://www.uwe-sieber.de/usbstick_e.html">http://www.uwe-sieber.de/usbstick_e.html</a>
> 
> Bernie

Thanks for the observation & link Bernie.

I'm using WinXP, and 4 different "removable drives" have shown up as present,
as far as I remember, from first time I turned on the system, before ever
mounting
any usb flashdrives.  Those are the drives that show up from GetLogicalDrives.
Any time I mount a usb drive, I unmount it via the "safely remove hardware"
icon in systray, which is currently showing those same 4 not actually present
drives; when I do mount a usb flash drive, it shows up also, and then
dissappears from the "safely remove hardware" list after I click there to unmount
it.

So my problem *seems* (?) to be, how to discern if a drive that is asserted 
by the system to be "there" is actually "ready" or not.  I thought to use 
"dir" to test that, but it brought up non-fatal errors which required user
clicks in a message box to continue, which is not desireable. 

Dan

new topic     » goto parent     » topic index » view message » categorize

4. Re: [WIN] GetLogicalDrives returns drives NOT present

Dan Moyer wrote:
> 
> Bernie Ryan wrote:
> > 
> > Dan Moyer wrote:
> > > 
> > > 
> > > When I wrap the function GetLogicalDrives, it works, except that it 
> > > returns drive numbers for drives that aren't actually there yet, exactly
> > > as
> > > "My Computer" does, ie, usb drives that aren't currently plugged in.  And
> > > then
> > > if I use "dir" to see if a drive is "ready", I get a non-fatal error
> > > message.
> > >  
> > > 
> > > What I was trying to do was find out what drives are on the system, and
> > > then
> > > if they were removable or not.  But I don't want to check drives that
> > > aren't
> > > actually there.
> > > 
> > > Any suggestions??
> >  
> > Dan:
> > 
> >     Be sure that you unmount the USB drives before you remove them.
> > 
> >     Windows when it loads assigns the drive numbers when it boots
> > 
> >     and when you remove a USB drive it's drive number does not go
> > 
> >     away.
> > 
> >     You did't say what operating system you are using which may make a
> > 
> >     difference.
> > 
> >     Here is a link that might help:
> > 
> >     <a
> >     href="http://www.uwe-sieber.de/usbstick_e.html">http://www.uwe-sieber.de/usbstick_e.html</a>
> > 
> > Bernie
> 
> Thanks for the observation & link Bernie.
> 
> I'm using WinXP, and 4 different "removable drives" have shown up as present,
> as far as I remember, from first time I turned on the system, before ever
> mounting
> any usb flashdrives.  Those are the drives that show up from GetLogicalDrives.
> Any time I mount a usb drive, I unmount it via the "safely remove hardware"
> icon in systray, which is currently showing those same 4 not actually present
> drives; when I do mount a usb flash drive, it shows up also, and then
> dissappears
> from the "safely remove hardware" list after I click there to unmount it.  
> 
> So my problem *seems* (?) to be, how to discern if a drive that is asserted
> 
> by the system to be "there" is actually "ready" or not.  I thought to use 
> "dir" to test that, but it brought up non-fatal errors which required user
> clicks in a message box to continue, which is not desireable. 
> 
> Dan

GetLogicalDrives doesn't seem the way to go.
Instead, the code at the following address is supposed to list all available
volumes with their paths, which looks like what you are after:
http://msdn2.microsoft.com/en-us/library/bb891980(VS.85).aspx
Of course, this is in C, but the code is clean and pretty straightforward to
translate.

CChris

new topic     » goto parent     » topic index » view message » categorize

5. Re: [WIN] GetLogicalDrives returns drives NOT present

Dan Moyer wrote:
> 
> Bernie Ryan wrote:
> > 
> > Dan Moyer wrote:
> > > 
> > > 
> > > When I wrap the function GetLogicalDrives, it works, except that it 
> > > returns drive numbers for drives that aren't actually there yet, exactly
> > > as
> > > "My Computer" does, ie, usb drives that aren't currently plugged in.  And
> > > then
> > > if I use "dir" to see if a drive is "ready", I get a non-fatal error
> > > message.
> > >  
> > > 
> > > What I was trying to do was find out what drives are on the system, and
> > > then
> > > if they were removable or not.  But I don't want to check drives that
> > > aren't
> > > actually there.
> > > 
> > > Any suggestions??
> >  
> > Dan:
> > 
> >     Be sure that you unmount the USB drives before you remove them.
> > 
> >     Windows when it loads assigns the drive numbers when it boots
> > 
> >     and when you remove a USB drive it's drive number does not go
> > 
> >     away.
> > 
> >     You did't say what operating system you are using which may make a
> > 
> >     difference.
> > 
> >     Here is a link that might help:
> > 
> >     <a
> >     href="http://www.uwe-sieber.de/usbstick_e.html">http://www.uwe-sieber.de/usbstick_e.html</a>
> > 
> > Bernie
> 
> Thanks for the observation & link Bernie.
> 
> I'm using WinXP, and 4 different "removable drives" have shown up as present,
> as far as I remember, from first time I turned on the system, before ever
> mounting
> any usb flashdrives.  Those are the drives that show up from GetLogicalDrives.
> Any time I mount a usb drive, I unmount it via the "safely remove hardware"
> icon in systray, which is currently showing those same 4 not actually present
> drives; when I do mount a usb flash drive, it shows up also, and then
> dissappears
> from the "safely remove hardware" list after I click there to unmount it.  
> 
> So my problem *seems* (?) to be, how to discern if a drive that is asserted
> 
> by the system to be "there" is actually "ready" or not.  I thought to use 
> "dir" to test that, but it brought up non-fatal errors which required user
> clicks in a message box to continue, which is not desireable. 
> 

Dan:

  Get a list of drive drive letters using a Window function.
 
  Then I don't know if XP would allow you to write in Euphoria Assembler
  
  function that would use interrupt 13 ( INT 13,1 - Disk Status ) to

  check the status of each of the drive letters that you found with

  the windows function.

  Using the interrupt would eliminate the OS error message.

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

6. Re: [WIN] GetLogicalDrives returns drives NOT present

CChris wrote:
> 
> Dan Moyer wrote:
> > 
> > Bernie Ryan wrote:
> > > 
> > > Dan Moyer wrote:
> > > > 
> > > > 
> > > > When I wrap the function GetLogicalDrives, it works, except that it 
> > > > returns drive numbers for drives that aren't actually there yet, exactly
> > > > as
> > > > "My Computer" does, ie, usb drives that aren't currently plugged in. 
> > > > And then
> > > > if I use "dir" to see if a drive is "ready", I get a non-fatal error
> > > > message.
> > > >  
> > > > 
> > > > What I was trying to do was find out what drives are on the system, and
> > > > then
> > > > if they were removable or not.  But I don't want to check drives that
> > > > aren't
> > > > actually there.
> > > > 
> > > > Any suggestions??
> > >  
> > > Dan:
> > > 
> > >     Be sure that you unmount the USB drives before you remove them.
> > > 
> > >     Windows when it loads assigns the drive numbers when it boots
> > > 
> > >     and when you remove a USB drive it's drive number does not go
> > > 
> > >     away.
> > > 
> > >     You did't say what operating system you are using which may make a
> > > 
> > >     difference.
> > > 
> > >     Here is a link that might help:
> > > 
> > >     <a
> > >     href="http://www.uwe-sieber.de/usbstick_e.html">http://www.uwe-sieber.de/usbstick_e.html</a>
> > > 
> > > Bernie
> > 
> > Thanks for the observation & link Bernie.
> > 
> > I'm using WinXP, and 4 different "removable drives" have shown up as
> > present,
> > as far as I remember, from first time I turned on the system, before ever
> > mounting
> > any usb flashdrives.  Those are the drives that show up from
> > GetLogicalDrives.
> > Any time I mount a usb drive, I unmount it via the "safely remove hardware"
> > icon in systray, which is currently showing those same 4 not actually
> > present
> > drives; when I do mount a usb flash drive, it shows up also, and then
> > dissappears
> > from the "safely remove hardware" list after I click there to unmount it.  
> > 
> > So my problem *seems* (?) to be, how to discern if a drive that is asserted
> > 
> > by the system to be "there" is actually "ready" or not.  I thought to use 
> > "dir" to test that, but it brought up non-fatal errors which required user
> > clicks in a message box to continue, which is not desireable. 
> > 
> > Dan
> 
> GetLogicalDrives doesn't seem the way to go.
> Instead, the code at the following address is supposed to list all available
> volumes with their paths, which looks like what you are after:
> <a
> href="http://msdn2.microsoft.com/en-us/library/bb891980">http://msdn2.microsoft.com/en-us/library/bb891980</a>(VS.85).aspx
> Of course, this is in C, but the code is clean and pretty straightforward to
> translate.
> 
> CChris

Chris: 
I kinda thought *logical* drives might be at least part of the problem I'm
having, but I don't think I can decipher/translate the C code.  I'm
wondering if there isn't some way to defeat the presentation of the error
messages?  I thought there is something along those line in Win32Lib?


And Bernie wrote:

> Dan:
> 
>   Get a list of drive drive letters using a Window function.
>  
>   Then I don't know if XP would allow you to write in Euphoria Assembler
>   
>   function that would use interrupt 13 ( INT 13,1 - Disk Status ) to
> 
>   check the status of each of the drive letters that you found with
> 
>   the windows function.
> 
>   Using the interrupt would eliminate the OS error message.
> 
> Bernie

Bernie:
Yeah, I can get the list of drives ok, and if I use the "dir" function,
if equal(dir(  aDrive & "://"  ) , -1) then
         puts(1, "drive not ready")
       end if 

I actually DO get accurate results, the "phantom" drives show as not ready,
and actual mounted flashdrive shows as ready, but with error messages
allowing user to select "continue" presenting for each "not ready" drive.
  But I'd hate to have to try
to write assembly code right now if at all avoidable.  Thanks for the 
suggestion, though :)

If I could just defeat that #$% error message, my code would work!

Dan

new topic     » goto parent     » topic index » view message » categorize

7. Re: [WIN] GetLogicalDrives returns drives NOT present

When trying to use:
if equal(dir(  aDrive & "://"  ) , -1) then
          puts(1, "drive not ready")
        end if 
 

to check if a listed drive is "ready" (actually present when some drives
are reported present when they're not), I get error messages when the
routine encounters drives that are NOT ready. 

Searching for how to suppress the error message, I find the following, in 
what I think I recognize as Pascal code.

Does it seem like it's likely to do what I want, and does anyone have any 
suggestions for translating it into Euphoria code?  :)

Dan

You can use the Windows API Function SetErrorMode() To suppress the
Window's critical Error dialog.

Function IsDriveReady(DriveLetter : char) : bool;
var
  OldErrorMode : Word;
  OldDirectory : String;
begin
  OldErrorMode := SetErrorMode(SEM_NOOPENFILEERRORBOX);
  GetDir(0, OldDirectory);
  {$I-}
    Chdir(DriveLetter + ':\');
  {$I+}
   If IoResult <> 0 Then
     Result := False 
   Else
     Result := True;

  Chdir(OldDirectory);
  SetErrorMode(OldErrorMode);
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
  If Not IsDriveReady('A') then
    ShowMessage('Drive Not Ready') else
    ShowMessage('Drive is Ready');
End;

new topic     » goto parent     » topic index » view message » categorize

8. Re: [WIN] GetLogicalDrives returns drives NOT present

Dan Moyer wrote:
> 
> CChris wrote:
> > 
> > Dan Moyer wrote:
> > > 
> > > Bernie Ryan wrote:
> > > > 
> > > > Dan Moyer wrote:
> > > > > 
> > > > > 
> > > > > When I wrap the function GetLogicalDrives, it works, except that it 
> > > > > returns drive numbers for drives that aren't actually there yet,
> > > > > exactly
> as</font></i>
> > > > > "My Computer" does, ie, usb drives that aren't currently plugged in. 
> > > > > And
> then</font></i>
> > > > > if I use "dir" to see if a drive is "ready", I get a non-fatal error
> > > > > message.
> > > > >  
> > > > > 
> > > > > What I was trying to do was find out what drives are on the system,
> > > > > and then
> > > > > if they were removable or not.  But I don't want to check drives that
> > > > > aren't
> > > > > actually there.
> > > > > 
> > > > > Any suggestions??
> > > >  
> > > > Dan:
> > > > 
> > > >     Be sure that you unmount the USB drives before you remove them.
> > > > 
> > > >     Windows when it loads assigns the drive numbers when it boots
> > > > 
> > > >     and when you remove a USB drive it's drive number does not go
> > > > 
> > > >     away.
> > > > 
> > > >     You did't say what operating system you are using which may make a
> > > > 
> > > >     difference.
> > > > 
> > > >     Here is a link that might help:
> > > > 
> > > >     <a
> > > >     href="http://www.uwe-sieber.de/usbstick_e.html">http://www.uwe-sieber.de/usbstick_e.html</a>
> > > > 
> > > > Bernie
> > > 
> > > Thanks for the observation & link Bernie.
> > > 
> > > I'm using WinXP, and 4 different "removable drives" have shown up as
> > > present,
> > > as far as I remember, from first time I turned on the system, before ever
> > > mounting
> > > any usb flashdrives.  Those are the drives that show up from
> > > GetLogicalDrives.
> > > Any time I mount a usb drive, I unmount it via the "safely remove
> > > hardware"
> > > icon in systray, which is currently showing those same 4 not actually
> > > present
> > > drives; when I do mount a usb flash drive, it shows up also, and then
> > > dissappears
> > > from the "safely remove hardware" list after I click there to unmount it. 
> > >
> > > 
> > > So my problem *seems* (?) to be, how to discern if a drive that is
> > > asserted
> > > 
> > > by the system to be "there" is actually "ready" or not.  I thought to use 
> > > "dir" to test that, but it brought up non-fatal errors which required user
> > > clicks in a message box to continue, which is not desireable. 
> > > 
> > > Dan
> > 
> > GetLogicalDrives doesn't seem the way to go.
> > Instead, the code at the following address is supposed to list all available
> > volumes with their paths, which looks like what you are after:
> > <a
> > href="http://msdn2.microsoft.com/en-us/library/bb891980">http://msdn2.microsoft.com/en-us/library/bb891980</a>(VS.85).aspx
> > Of course, this is in C, but the code is clean and pretty straightforward to
> > translate.
> > 
> > CChris
> 
> Chris: 
> I kinda thought *logical* drives might be at least part of the problem I'm
> having, but I don't think I can decipher/translate the C code.  I'm
> wondering if there isn't some way to defeat the presentation of the error
> messages?  I thought there is something along those line in Win32Lib?
> 

If what you get is a dialog box that allows you to continue executing
(yes/no/cancel), then calling setWarning(0) before running your code will
suppress it. I must say that it is not the recommended way...

I'll try to find some time to post a translation of the code at MSDN. Actually,
it's pretty simple: get all known volume strings, then retrieve all the paths for
each of those strings. Because there are sequences of chars everywhere, the code
isn't as short as you might exect at first, but... it may be worth to try again.

</snip>

CChris

new topic     » goto parent     » topic index » view message » categorize

9. Re: [WIN] GetLogicalDrives returns drives NOT present

Dan Moyer wrote:
> 
> 
> When trying to use:
>  }}}
<eucode>
>        if equal(dir(  aDrive & "://"  ) , -1) then
>           puts(1, "drive not ready")
>         end if 
>  </eucode>
{{{

> to check if a listed drive is "ready" (actually present when some drives
> are reported present when they're not), I get error messages when the
> routine encounters drives that are NOT ready. 
> 
> Searching for how to suppress the error message, I find the following, in 
> what I think I recognize as Pascal code.
> 
> Does it seem like it's likely to do what I want, and does anyone have any 
> suggestions for translating it into Euphoria code?  :)
> 
> Dan
> 
> You can use the Windows API Function SetErrorMode() To suppress the
> Window's critical Error dialog.
> 
> Function IsDriveReady(DriveLetter : char) : bool;
> var
>   OldErrorMode : Word;
>   OldDirectory : String;
> begin
>   OldErrorMode := SetErrorMode(SEM_NOOPENFILEERRORBOX);
>   GetDir(0, OldDirectory);
>   {$I-}
>     Chdir(DriveLetter + ':\');
>   {$I+}
>    If IoResult <> 0 Then
>      Result := False 
>    Else
>      Result := True;
> 
>   Chdir(OldDirectory);
>   SetErrorMode(OldErrorMode);
> End;
> 
> procedure TForm1.Button1Click(Sender: TObject);
> begin
>   If Not IsDriveReady('A') then
>     ShowMessage('Drive Not Ready') else
>     ShowMessage('Drive is Ready');
> End;

That would work too. Suppressing system errors is something you have to do at
some point while developing a piece of software, most importantly a driver, so
the command has to be there. But I certainly wouldn't recommand doing that as
part of normal code operation.
Try perhaps something cleaner using GetLogicalDriveStrings() and
GetVolumePathNamesFromVolumeName() APIs.

CChris

new topic     » goto parent     » topic index » view message » categorize

10. Re: [WIN] GetLogicalDrives returns drives NOT present

<<SNIP>>
> > 
> > Chris: 
> > I kinda thought *logical* drives might be at least part of the problem I'm
> > having, but I don't think I can decipher/translate the C code.  I'm
> > wondering if there isn't some way to defeat the presentation of the error
> > messages?  I thought there is something along those line in Win32Lib?
> > 
> 
> If what you get is a dialog box that allows you to continue executing
> (yes/no/cancel),
> then calling setWarning(0) before running your code will suppress it. I must
> say that it is not the recommended way...
> 
> I'll try to find some time to post a translation of the code at MSDN.
> Actually,
> it's pretty simple: get all known volume strings, then retrieve all the paths
> for each of those strings. Because there are sequences of chars everywhere,
> the code isn't as short as you might exect at first, but... it may be worth
> to try again.
> 
> </snip>
> 
> CChris

CChris,

Thanks, but never mind, I found a "getVolumeInformation()" function
in a set of includes by Austin Cathey in my system, although I haven't yet
re-found it in contributions, where I must have got it from at some time.

That's pretty much what you originally suggested I do!  :)

Thanks for the effort, though.

Dan

new topic     » goto parent     » topic index » view message » categorize

11. Re: [WIN] GetLogicalDrives returns drives NOT present

Dan Moyer wrote:
> 
> <<SNIP>>
> > > 
> > > Chris: 
> > > I kinda thought *logical* drives might be at least part of the problem I'm
> > > having, but I don't think I can decipher/translate the C code.  I'm
> > > wondering if there isn't some way to defeat the presentation of the error
> > > messages?  I thought there is something along those line in Win32Lib?
> > > 
> > 
> > If what you get is a dialog box that allows you to continue executing
> > (yes/no/cancel),
> > then calling setWarning(0) before running your code will suppress it. I must
> > say that it is not the recommended way...
> > 
> > I'll try to find some time to post a translation of the code at MSDN.
> > Actually,
> > it's pretty simple: get all known volume strings, then retrieve all the
> > paths
> > for each of those strings. Because there are sequences of chars everywhere,
> > the code isn't as short as you might exect at first, but... it may be worth
> > to try again.
> > 
> > </snip>
> > 
> > CChris
> 
> CChris,
> 
> Thanks, but never mind, I found a "getVolumeInformation()" function
> in a set of includes by Austin Cathey in my system, although I haven't yet
> re-found it in contributions, where I must have got it from at some time.
> 
> That's pretty much what you originally suggested I do!  :)
> 
> Thanks for the effort, though.
> 
> Dan

Oops, the "getVolumeInformation" was really by William Heimbigner, it used a
dll handling include that was by Austin Cathey, that's what confused me,
I thought they were both by the same person. 

Dan

new topic     » goto parent     » topic index » view message » categorize

12. Re: [WIN] GetLogicalDrives returns drives NOT present

Dan Moyer wrote:
> 
> Dan Moyer wrote:
> > 
> > <<SNIP>>
> > > > 
> > > > Chris: 
> > > > I kinda thought *logical* drives might be at least part of the problem
> > > > I'm
> > > > having, but I don't think I can decipher/translate the C code.  I'm
> > > > wondering if there isn't some way to defeat the presentation of the
> > > > error
> > > > messages?  I thought there is something along those line in Win32Lib?
> > > > 
> > > 
> > > If what you get is a dialog box that allows you to continue executing
> > > (yes/no/cancel),
> > > then calling setWarning(0) before running your code will suppress it. I
> > > must
> > > say that it is not the recommended way...
> > > 
> > > I'll try to find some time to post a translation of the code at MSDN.
> > > Actually,
> > > it's pretty simple: get all known volume strings, then retrieve all the
> > > paths
> > > for each of those strings. Because there are sequences of chars
> > > everywhere,
> > > the code isn't as short as you might exect at first, but... it may be
> > > worth
> > > to try again.
> > > 
> > > </snip>
> > > 
> > > CChris
> > 
> > CChris,
> > 
> > Thanks, but never mind, I found a "getVolumeInformation()" function
> > in a set of includes by Austin Cathey in my system, although I haven't yet
> > re-found it in contributions, where I must have got it from at some time.
> > 
> > That's pretty much what you originally suggested I do!  :)
> > 
> > Thanks for the effort, though.
> > 
> > Dan
> 
> Oops, the "getVolumeInformation" was really by William Heimbigner, it used a
> dll handling include that was by Austin Cathey, that's what confused me,
> I thought they were both by the same person. 
> 
> Dan

Try running this under exwc.exe, it works under XP Pro at work. No errors, hence
no error handling. Lines may wrap:
include dll.e
include machine.e
constant k32=open_dll("kernel32.dll")
if not k32 then 
crash_message("Couldn't find kernel32.dll; perhaps not running under
    Windows.")
    abort(1)
end if
constant
glds=define_c_func(k32,"GetLogicalDriveStringsA",{C_LONG,C_POINTER},C_LONG)
if glds=-1 then
crash_message("The GetLogicalDriveStringsA API is available only under Win
    2K Pro, XP or later")
    abort(1)
end if
constant all_string_sizes = c_func(glds,{0,0})
if not all_string_sizes then
    crash_message("GetLogicalDriveStringsA failed for some reason.")
    abort(1)
end if

-- retrieve all volume names
atom void
atom string_buffer string_buffer = allocate(all_string_sizes)
void = c_func(glds,{all_string_sizes,string_buffer})
if not void then
    crash_message("GetLogicalDriveStringsA failed for some reason.")
    abort(1)
end if
constant strlen = define_c_func(k32,"lstrlenA",{C_POINTER},C_LONG)
if strlen=-1 then
crash_message("lstrlen could not be found. Perhaps this is an Unicode build
    of Windows.")
    abort(1)
end if

puts(1,"Known drives:\n")
puts(1,repeat('=',13)&"\n\n")
-- scan all volumes
integer len_str
while 1 do -- read array of volume names
    -- how long is the volume string?
    len_str = c_func(strlen,{string_buffer})
    if not len_str then -- reached the end
        exit
    end if

    puts(1,peek({string_buffer,len_str})&"\n")

    -- next
    string_buffer += len_str+1

end while
?machine_func(26,0)


It gives me all available drives, some of them being mapped network drives, not
listing the CD-ROM drive where there's no cd, not listing USB ports with nothing
connected to it.

CChris

new topic     » goto parent     » topic index » view message » categorize

13. Re: [WIN] GetLogicalDrives returns drives NOT present

CChris wrote:
<snip>

> Try running this under exwc.exe, it works under XP Pro at work. No errors,
> hence
> no error handling. Lines may wrap:
> }}}
<eucode>
> include dll.e
> include machine.e
> constant k32=open_dll("kernel32.dll")
> if not k32 then 
>     crash_message("Couldn't find kernel32.dll; perhaps not running under
>     Windows.")
>     abort(1)
> end if
> constant
> glds=define_c_func(k32,"GetLogicalDriveStringsA",{C_LONG,C_POINTER},C_LONG)
> if glds=-1 then
>     crash_message("The GetLogicalDriveStringsA API is available only under Win
>     2K Pro, XP or later")
>     abort(1)
> end if
> constant all_string_sizes = c_func(glds,{0,0})
> if not all_string_sizes then
>     crash_message("GetLogicalDriveStringsA failed for some reason.")
>     abort(1)
> end if
> 
> -- retrieve all volume names
> atom void
> atom string_buffer string_buffer = allocate(all_string_sizes)
> void = c_func(glds,{all_string_sizes,string_buffer})
> if not void then
>     crash_message("GetLogicalDriveStringsA failed for some reason.")
>     abort(1)
> end if
> constant strlen = define_c_func(k32,"lstrlenA",{C_POINTER},C_LONG)
> if strlen=-1 then
>     crash_message("lstrlen could not be found. Perhaps this is an Unicode
>     build of Windows.")
>     abort(1)
> end if
> 
> puts(1,"Known drives:\n")
> puts(1,repeat('=',13)&"\n\n")
> -- scan all volumes
> integer len_str
> while 1 do -- read array of volume names
>     -- how long is the volume string?
>     len_str = c_func(strlen,{string_buffer})
>     if not len_str then -- reached the end
>         exit
>     end if
> 
>     puts(1,peek({string_buffer,len_str})&"\n")
> 
>     -- next
>     string_buffer += len_str+1
> 
> end while
> ?machine_func(26,0)
> </eucode>
{{{

> 
> It gives me all available drives, some of them being mapped network drives,
> not listing the CD-ROM drive where there's no cd, not listing USB ports with
> nothing connected to it.
> 
> CChris

thanks for the effort Chris, 
On my system it still returns the "phantom" usb drives, same as 
"My Computer" or "Windows Explorer" does.  But using the "getVolumes" 
function, & selecting those which ARE removable drives, and those which DO
have some file system indicated does succeed in only returning the ACTUAL
removable drives on the system.

when I get it cleaned up I'll send it in so you can see it, sorry if I
wasted your time.

Dan

new topic     » goto parent     » topic index » view message » categorize

14. Re: [WIN] GetLogicalDrives returns drives NOT present

Chris,

Here's what works for me, get the include from user contrib, I just removed some
unused vars from in for my use:
include win32lib.ew
include getvolumeinfo.ew  -- FROM USER CONTRIBS



constant xGetLogicalDrives = registerw32Function(kernel32,"GetLogicalDrives",
{},C_LONG  )
,xGetDriveType = registerw32Function(kernel32,"GetDriveTypeA",
        {C_POINTER},C_LONG  )
          
integer aResult, theResult
integer dummy
sequence volumeResult, drivesPresent

procedure CheckForRemovable(sequence aDrive)
   puts(1, aDrive & "://") 
   if w32Func(xGetDriveType, {aDrive & "://"}) = 2 then
      puts(1, " REMOVABLE DRIVE")
      volumeResult = getVolumeInformation (aDrive & "://")

      if equal(volumeResult[5], {}) then
         puts(1, " drive not ready")
      else
         puts(1, " READY")
      end if 
   else
      puts(1, "non removable drive")
   end if

end procedure

aResult= w32Func(xGetLogicalDrives, {})
puts(1, sprint(aResult)& "\n")
theResult = aResult
puts(1, " bits: " & sprint(int_to_bits(aResult, 26)) & " ** \n")
drivesPresent = int_to_bits(aResult, 26) 
puts(1, "drives present: " & drivesPresent)

puts(1, "\n\n")


puts(1, "drives present: " & sprint(drivesPresent) & "\n")
for n = 1 to length(drivesPresent) do
  if equal(drivesPresent[n], 1) then
     CheckForRemovable({n + 64} )
  end if
  puts(1, "\n")
end for


dummy = wait_key()


new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu