Recent

Author Topic: How to detect unmounted drive from ShellTreeView before Error  (Read 619 times)

jarmo.kervinen@elisanet.f

  • Newbie
  • Posts: 2
How to detect unmounted drive from ShellTreeView before Error
« on: January 14, 2020, 05:12:12 pm »

My ShellTreeView vindow shows in the start of program signs of all drives (C:\ ...E:\).
Drive E is not mounted. If I click it, it raises Error (32 bit Windows 7). In other PC (64 bit Windows 7) No error appears.
How to detect in OnEnter or by signing in  ShellTreeView, that some drive in unmounted?
Jarmo Kervinen

Bart

  • Hero Member
  • *****
  • Posts: 3850
    • Bart en Mariska's Webstek
Re: How to detect unmounted drive from ShellTreeView before Error
« Reply #1 on: January 14, 2020, 06:12:02 pm »
This may help?

Code: Pascal  [Select][+][-]
  1. uses
  2.   Windows;
  3.  
  4. function DiskInDrive(Drive: Char): Boolean;
  5. var
  6.   ErrorMode: word;
  7. begin
  8.   { maak er een hoofdletter van }
  9.   Drive := UpCase(Drive);
  10.   if not (Drive in ['A'..'Z']) then
  11.     raise EConvertError.Create('Geen geldige stationsaanduiding: '+Drive+':');
  12.   { schakel kritieke fouten uit }
  13.   ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  14.   try
  15.     { drive 1 = a, 2 = b, 3 = c, etc. }
  16.     if DiskSize(Ord(Drive) - Ord('A') + 1) = -1 then
  17.       Result := False
  18.     else
  19.       Result := True;
  20.   finally
  21.     { restore old error mode }
  22.     SetErrorMode(ErrorMode);
  23.   end;
  24. end;

It's Windows only of course, so you'll have to ifdef it.

Bart

Thaddy

  • Hero Member
  • *****
  • Posts: 10272
Re: How to detect unmounted drive from ShellTreeView before Error
« Reply #2 on: January 14, 2020, 06:46:41 pm »
@Bart
That works for local drives only.
You also have to account for canonical paths.
I am more like donkey than shrek

Bart

  • Hero Member
  • *****
  • Posts: 3850
    • Bart en Mariska's Webstek
Re: How to detect unmounted drive from ShellTreeView before Error
« Reply #3 on: January 14, 2020, 10:48:59 pm »
You also have to account for canonical paths.

Huh?
What is that and would that show up as a drive letter in a TShellTreeView?
(The question was about drives in a TShellTreeView)

Bart

jarmo.kervinen@elisanet.f

  • Newbie
  • Posts: 2
Re: How to detect unmounted drive from ShellTreeView before Error
« Reply #4 on: January 15, 2020, 09:33:23 am »
Thank you Bert. The solution was critical in my program.
Jarmo

Bart

  • Hero Member
  • *****
  • Posts: 3850
    • Bart en Mariska's Webstek
Re: How to detect unmounted drive from ShellTreeView before Error
« Reply #5 on: January 15, 2020, 03:30:21 pm »
Thank you Bert.

Bert and Ernie are from Sesamestreet.
I share my name with one of the Simpsons  (I would have preferred that Ernie's friend were called Bart though)O:-)

Glad to be of help though.

Bart

 

TinyPortal © 2005-2018