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

Windows specific forum
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

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

Post 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
Last edited by Kukulkan on Wed Sep 16, 2015 1:24 pm, edited 1 time in total.
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

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

Post 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
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

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

Post 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
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

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

Post 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.
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

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

Post 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.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

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

Post by Kukulkan »

Hi PureGuy,

thanks, I missed that! Great :-)
Post Reply