Some functions to retrieve volume name / Delete and Set MountPoint
Code: Select all
;/ Droopy 25/10/05
; PureBasic 3.94
; MountVolName : Return VolumeName as String or "" if volume is not mounted
; UnMountVolume : Return 1 if success / 0 if fail
; MountVol : Return 1 if success / 0 if fail
; MountVolChange : Change Drive letter : Return if success : 1
; if Fail : 0 Cannot Mount Destination / 2 Cannot Unmount Source / 3 Destination already Mounted / 4 Source not mounted
Procedure.s MountVolName(Drive.s)
If Right(Drive,1)<>"\" : Drive+"\":EndIf
VolumeName.s=Space(255)
VolumeMountPoint.s=Drive
OpenLibrary(0,"Kernel32.dll")
Retour=CallFunction(0,"GetVolumeNameForVolumeMountPointA",@VolumeMountPoint,@VolumeName,255)
CloseLibrary(0)
If Retour
ProcedureReturn VolumeName
EndIf
EndProcedure
Procedure UnMountVolume(Drive.s)
If Right(Drive,1)<>"\" : Drive+"\":EndIf
VolumeMountPoint.s=Drive
OpenLibrary(0,"Kernel32.dll")
Retour=CallFunction(0,"DeleteVolumeMountPointA",@VolumeMountPoint)
CloseLibrary(0)
If Retour<>0 : Retour=1 : EndIf
ProcedureReturn Retour
EndProcedure
Procedure MountVol(Drive.s,MountPoint.s)
If Right(Drive,1)<>"\" : Drive+"\":EndIf
VolumeMountPoint.s=Drive
OpenLibrary(0,"Kernel32.dll")
Retour=CallFunction(0,"SetVolumeMountPointA",@VolumeMountPoint,@MountPoint)
CloseLibrary(0)
If Retour<>0 : Retour=1 : EndIf
ProcedureReturn Retour
EndProcedure
Procedure MountVolChange(Source.s,Destination.s)
If Right(Source,1)<>"\" : Source+"\":EndIf
If Right(Destination,1)<>"\" : Destination+"\":EndIf
VolId.s=MountVolName(Source)
If VolId<>"" ;/ Source existe
If MountVolName(Destination)="" ;/ Destination non montée
If UnMountVolume(Source) ;/ Le suppression s'est bien passé
Retour=MountVol(Destination,VolId) ;/ Le montage s'est bien passé
Else
Retour=2 ;/ Suppression mal passée
EndIf
Else ;/ Destination déjà montée
Retour=3
EndIf
Else ;/ Pas de montage dans le lecteur Source
Retour=4
EndIf
ProcedureReturn Retour
EndProcedure
;/ Test1 : List All Mounted Volumes
For n=65 To 90
Lecteur.s=Chr(n)+":\"
Temp.s=MountVolName(Lecteur)
If Temp<>""
Message.s+Lecteur+" "+Temp+#CRLF$
EndIf
Next
MessageRequester("Volume Information",Message,#MB_ICONINFORMATION)
;/ Test2 : Change Drive letter of my USB Key
If MessageRequester("Change Drive Letter ?","Do you want to change drive letter ?",#PB_MessageRequester_YesNo)=6
Select MountVolChange("Z:","U:")
Case 0
MessageRequester("Changing Drive Letter","Cannot Mount Destination",#MB_ICONERROR )
Case 1
MessageRequester("Changing Drive Letter","Success",#MB_ICONINFORMATION )
Case 2
MessageRequester("Changing Drive Letter","Cannot Unmount Source",#MB_ICONERROR )
Case 3
MessageRequester("Changing Drive Letter","Destination already Mounted",#MB_ICONERROR )
Case 4
MessageRequester("Changing Drive Letter","Source not mounted",#MB_ICONERROR )
EndSelect
EndIf