Author Topic: Using _DIREXISTS with BitLocker encrypted drives  (Read 2248 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Using _DIREXISTS with BitLocker encrypted drives
« on: January 26, 2021, 05:13:05 am »
When checking for the existence of a drive letter, I have been using the _DIREXISTS function.

For example:

IF _DIREXISTS(D:) then
   PRINT "Drive letter D: exists on this system"
END IF

However, if a drive is BitLocker protected AND that drive is currently locked, then the _DIREXISTS for that drive letter will return false leading to the erroneous conclusion that the drive letter is available.

To work around this, if _DIREXISTS returns false, I always follow up by running a "manage-bde -status D:" (or whatever drive letter) via a SHELL command and capturing / parsing the output.

So, this leads me to my question: Is there any more foolproof way to determine a drive letter's existence? There is the _DIREXISTS function, as well as the _FILEEXISTS function, but no _DRIVEEXISTS function or anything similar as far as I can tell. My workaround works, just wondering if there is a more direct test of the existence of a drive letter.



Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Using _DIREXISTS with BitLocker encrypted drives
« Reply #1 on: January 26, 2021, 06:59:03 am »
Using the WinAPI (I assume you are on Windows OS),

Code: QB64: [Select]
  1.     FUNCTION GetLogicalDriveStringsA& (BYVAL bufSize&, buffer$)
  2.  
  3. '--- get available drives once during your program init procedure ---
  4. DIM SHARED allDrives$
  5. buffer$ = SPACE$(112)
  6. length% = GetLogicalDriveStringsA&(LEN(buffer$), buffer$)
  7. allDrives$ = ""
  8. FOR position% = 1 TO length% STEP 4
  9.     allDrives$ = allDrives$ + MID$(buffer$, position%, 1)
  10. NEXT position%
  11.  
  12. '--- in your program flow test drives whenever needed (returns false(0) or true(-1)) ---
  13. PRINT DRIVEEXISTS%("A")
  14. PRINT DRIVEEXISTS%("B")
  15. PRINT DRIVEEXISTS%("C")
  16. PRINT DRIVEEXISTS%("D")
  17.  
  18. '--- a quick test function ---
  19. FUNCTION DRIVEEXISTS% (drv$)
  20. DRIVEEXISTS% = (INSTR(allDrives$, UCASE$(drv$)) > 0)
  21.  
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Using _DIREXISTS with BitLocker encrypted drives
« Reply #2 on: January 26, 2021, 02:00:57 pm »
Thanks, much appreciated.

I have to admit that I've never done anything using the WinAPI so I guess I better start educating myself on this :-)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Using _DIREXISTS with BitLocker encrypted drives
« Reply #3 on: January 26, 2021, 02:16:26 pm »
Thanks, much appreciated.

I have to admit that I've never done anything using the WinAPI so I guess I better start educating myself on this :-)

You won't be disappointed, but if you make your own routines, be advised there is lag when you poll the Windows libraries, so if you don't get the results you expected, put a _delay .3 ( or some other suitable value) in your code, to let the API return a value before polling for that value in your code.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/