Re: Drive/Volume Label
Posted: Sun Jan 17, 2010 5:32 pm
In windows 7 you can also get the volume lables from the registry at : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\VolumeInfoCache
http://www.purebasic.com
https://www.purebasic.fr/english/
ThanksSFSxOI wrote:In windows 7 you can also get the volume lables from the registry at : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\VolumeInfoCache
Code: Select all
Procedure.s GetDriveGUIDPath(szDrive.s, boolGUIDOnly = #False)
szDrive = Left(szDrive,1) + ":\"
Protected szVolumeGUIDPath.s = Space(100)
Protected dwVolumeGUIDSize.l = 100
Protected iDrive_Res.s = "", iDrive_CFR
Protected GuidStart, GuidEnd, szGUID.s
Protected hLib = OpenLibrary(#PB_Any,"kernel32.dll")
If hLib
CompilerIf #PB_Compiler_Unicode
iDrive_CFR = CallFunction(hLib, "GetVolumeNameForVolumeMountPointW", @szDrive, @szVolumeGUIDPath, @dwVolumeGUIDSize)
CompilerElse
iDrive_CFR = CallFunction(hLib, "GetVolumeNameForVolumeMountPointA", @szDrive, @szVolumeGUIDPath, @dwVolumeGUIDSize)
CompilerEndIf
If iDrive_CFR <> 0
iDrive_Res = szVolumeGUIDPath
If boolGUIDOnly
GuidStart = FindString(iDrive_Res, "{", 1)
GuidEnd = FindString(iDrive_Res, "}", GuidStart)
iDrive_Res = Mid(iDrive_Res, GuidStart, Len(iDrive_Res)-GuidStart)
EndIf
EndIf
CloseLibrary(hLib)
EndIf
ProcedureReturn iDrive_Res
EndProcedure
Thanks,SFSxOI wrote:Yes, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2 does exist in Windows 7, however, it does not contain any volume lables.
Code: Select all
Procedure.s GetDriveGUIDPath(szDrive.s, boolGUIDOnly = #False)
szDrive = Left(szDrive,1) + ":\"
Protected szVolumeGUIDPath.s = Space(100)
Protected dwVolumeGUIDSize.l = 100
Protected iDrive_Res.s = "", iDrive_CFR
Protected GuidStart, GuidEnd, szGUID.s
Protected hLib = OpenLibrary(#PB_Any,"kernel32.dll")
If hLib
CompilerIf #PB_Compiler_Unicode
iDrive_CFR = CallFunction(hLib, "GetVolumeNameForVolumeMountPointW", @szDrive, @szVolumeGUIDPath, @dwVolumeGUIDSize)
CompilerElse
iDrive_CFR = CallFunction(hLib, "GetVolumeNameForVolumeMountPointA", @szDrive, @szVolumeGUIDPath, @dwVolumeGUIDSize)
CompilerEndIf
If iDrive_CFR <> 0
iDrive_Res = szVolumeGUIDPath
If boolGUIDOnly
GuidStart = FindString(iDrive_Res, "{", 1)
GuidEnd = FindString(iDrive_Res, "}", GuidStart)
iDrive_Res = Mid(iDrive_Res, GuidStart, Len(iDrive_Res)-GuidStart)
EndIf
EndIf
CloseLibrary(hLib)
EndIf
ProcedureReturn iDrive_Res
EndProcedure
Procedure.s GetLabelFromGUID(szGUID.s)
Protected szLabel.s = Space(1024)
Protected szRetVal.s = ""
Protected lpLabel.l = 0
Protected lnLabel.l = 0
Protected lnType.l = 0
Protected Key
Protected qRes = 0
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\"+szGUID, 0, #KEY_ALL_ACCESS, @Key) = #ERROR_SUCCESS
If RegQueryValueEx_(Key, "_LabelFromReg", 0, @lnType, #NUL, @lnLabel) = #ERROR_SUCCESS
szLabel = Space(lnLabel+1)
If RegQueryValueEx_(Key, "_LabelFromReg", 0, @lnType, @szLabel, @lnLabel) = #ERROR_SUCCESS
szRetVal = szLabel
EndIf
EndIf
RegCloseKey_(Key)
EndIf
;If Not Trim(szRetVal)
szLabel.s = Space(1024)
lpLabel.l = 0
lnLabel.l = 0
lnType.l = 0
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\"+szGUID+"\_AutoRun\DefaultLabel", 0, #KEY_ALL_ACCESS, @Key) = #ERROR_SUCCESS
If RegQueryValueEx_(Key, "", 0, @lnType, #NUL, @lnLabel) = #ERROR_SUCCESS
szLabel = Space(lnLabel+1)
If RegQueryValueEx_(Key, "", 0, @lnType, @szLabel, @lnLabel) = #ERROR_SUCCESS
If Trim(szLabel)
szRetVal = szLabel
EndIf
EndIf
EndIf
RegCloseKey_(Key)
EndIf
;EndIf
ProcedureReturn szRetVal
EndProcedure
Code: Select all
;If Not Trim(szRetVal)
Code: Select all
;EndIf
Code: Select all
szDriveLabel.s = GetLabelFromGUID(GetDriveGUIDPath("C:\", #True))