Page 1 of 1

[solved]How to name a drive created using DefineDosDevice()?

Posted: Wed Sep 16, 2015 8:33 am
by Kukulkan
Hi,

I mount and unmount a drive using the code below (Windows). Is there a way to rename this drive?

Code: Select all

;{ -------- for DefineDosDevice() ------------
#DDD_RAW_TARGET_PATH       = $00000001
#DDD_REMOVE_DEFINITION     = $00000002
#DDD_EXACT_MATCH_ON_REMOVE = $00000004
#DDD_NO_BROADCAST_SYSTEM   = $00000008
;}

Procedure.i DriveLetterMount(Letter.s, DestinationPath.s)
  ; Create a volume with drive letter for the given destination path
  If Right(Letter.s, 1) <> ":": Letter.s = Letter.s + ":": EndIf
  If DefineDosDevice_(0, Letter.s, DestinationPath.s) = 0
    ProcedureReturn #False
  EndIf
  ProcedureReturn #True
EndProcedure

Procedure.i DriveLetterUnMount(Letter.s)
  ; Remove a volume that was created using DriveLetterMount() before
  If Right(Letter.s, 1) <> ":": Letter.s = Letter.s + ":": EndIf
  If DefineDosDevice_(#DDD_REMOVE_DEFINITION, Letter.s, 0) = 0
    ProcedureReturn #False
  EndIf
  ProcedureReturn #True
EndProcedure

Re: How to name a drive created using DefineDosDevice() API?

Posted: Wed Sep 16, 2015 9:16 am
by PureGuy
It works for volumes, but should work in your case, too.

Code: Select all

Procedure DriveSetLabel(sDrive.s, slabel.s)
  sDrive = Left(sDrive, 1) + ":\"
  ProcedureReturn SetVolumeLabel_(sDrive, slabel.s)
EndProcedure

Re: How to name a drive created using DefineDosDevice() API?

Posted: Wed Sep 16, 2015 10:33 am
by Kukulkan
Hello PureGuy,

Thanks, but I always get error 144 (ERROR_DIR_NOT_ROOT) as result (Error number determined using GetLastError()).

I'm able to rename the drive using right click and "rename" in file explorer. But if I open the drive properties, I'm not allowed to edit the volume name. Maybe there is a difference in the "Volume name" and the name displayed in file explorer?

Kukulkan

Re: How to name a drive created using DefineDosDevice() API?

Posted: Wed Sep 16, 2015 1:23 pm
by Kukulkan
I found that does not work for such devices. Instead, using the registry did the trick.

If I create a device X:, I use the following registry key to rename it:

Code: Select all

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\X\DefaultLabel [Default key]
This works fine!

BTW, would be great if someone would create an updated registry.pbi that also respects 64 and 32 bit and Unicode or ASCII. All the registry stuff I found in the forum was lacking one or the other option. Sadly, I do not have time to update all the functions of the includes. I only copied and fixed the parts I needed.

Re: [solved]How to name a drive created using DefineDosDevic

Posted: Wed Sep 16, 2015 2:05 pm
by PureGuy
The Registry Module (windows only) by ts-soft is very up to date.
ts-soft wrote: Wow6432Node is supported as flag!
x86, x64, ascii and unicode supported.

Re: [solved]How to name a drive created using DefineDosDevic

Posted: Wed Sep 16, 2015 2:17 pm
by Kukulkan
Hi PureGuy,

thanks, I missed that! Great :-)