Drive/Volume Label
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Drive/Volume Label
Hey all,
I'm working on something which requires both the volume name and label name of a specified drive,
But I don't know how to get the volume label, as specified in autorun.inf or via My Computer > Contextmenu on drive > Rename.
Can somebody help me out, I'm going nuts lol!
I'm working on something which requires both the volume name and label name of a specified drive,
But I don't know how to get the volume label, as specified in autorun.inf or via My Computer > Contextmenu on drive > Rename.
Can somebody help me out, I'm going nuts lol!
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
Re: Drive/Volume Label
Do you get any closer with this?
http://www.purebasic.fr/english/viewtop ... 13&t=40537
http://www.purebasic.fr/english/viewtop ... 13&t=40537
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Re: Drive/Volume Label
Thanks for the reply! 
Unfortunately GetVolumeInformation only supports the volume Name, I would
like to obtain the label as you see it in My Computer (even when modified in an autorun.inf etc.)
Thanks.

Unfortunately GetVolumeInformation only supports the volume Name, I would
like to obtain the label as you see it in My Computer (even when modified in an autorun.inf etc.)
Thanks.
Re: Drive/Volume Label
Code: Select all
Prototype FindFirstVolume(VolumeName.s, BufferLength.l)
Prototype FindNextVolume(hFindVolume.i, VolumeName.s, BufferLength.l)
Prototype FindVolumeClose(hFindVolume.i)
Define FindFirstVolume.FindFirstVolume
Define FindNextVolume.FindNextVolume
Define FindVolumeClose.FindVolumeClose
Define VolumeName.s = Space(#MAX_PATH)
Define hFindVolume.i
If OpenLibrary(0, "kernel32.dll")
CompilerIf #PB_Compiler_Unicode
FindFirstVolume = GetFunction(0, "FindFirstVolumeW")
FindNextVolume = GetFunction(0, "FindNextVolumeW")
CompilerElse
FindFirstVolume = GetFunction(0, "FindFirstVolumeA")
FindNextVolume = GetFunction(0, "FindNextVolumeA")
CompilerEndIf
FindVolumeClose = GetFunction(0, "FindVolumeClose")
hFindVolume = FindFirstVolume(VolumeName, #MAX_PATH)
If hFindVolume
Debug VolumeName
While FindNextVolume(hFindVolume, VolumeName, #MAX_PATH)
Debug VolumeName
Wend
FindVolumeClose(hFindVolume)
EndIf
CloseLibrary(0)
EndIf
Thomas
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Re: Drive/Volume Label
Thanks ts-soft,
This is useful too, thanks! But this is not really what i'm looking for right now.
I don't know how to use this GUID path to get the drive's label, possibly through registry?
This is useful too, thanks! But this is not really what i'm looking for right now.
I don't know how to use this GUID path to get the drive's label, possibly through registry?
Re: Drive/Volume Label
1- You can use WMI in windows like the next snippet
2- Or use WMIC in console
3- Or VOL in console
2- Or use WMIC in console
3- Or VOL in console
Code: Select all
#COINIT_MULTITHREAD=0
#RPC_C_AUTHN_LEVEL_CONNECT=2
#RPC_C_IMP_LEVEL_IDENTIFY=2
#EOAC_NONE=0
#RPC_C_AUTHN_WINNT=10
#RPC_C_AUTHZ_NONE=0
#RPC_C_AUTHN_LEVEL_CALL=3
#RPC_C_IMP_LEVEL_IMPERSONATE=3
#CLSCTX_INPROC_SERVER=1
#wbemFlagReturnImmediately=16
#wbemFlagForwardOnly=32
#IFlags = #wbemFlagReturnImmediately + #wbemFlagForwardOnly
#WBEM_INFINITE=$FFFFFFFF
#WMISeparator=","
;}
Procedure.l ansi2bstr(ansi.s)
size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0)
Dim unicode.w(size)
MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size)
ProcedureReturn SysAllocString_(@unicode())
EndProcedure
Procedure bstr2string (bstr)
Shared WMIResult.s
WMIResult.s = ""
pos=bstr
While PeekW (pos)
WMIResult=WMIResult+Chr(PeekW(pos))
pos=pos+2
Wend
ProcedureReturn @WMIResult
EndProcedure
ProcedureDLL.s WMI(WMICommand.s)
; WMI Initialize
CoInitializeEx_(0,#COINIT_MULTITHREAD)
hres=CoInitializeSecurity_(0, -1,0,0,#RPC_C_AUTHN_LEVEL_CONNECT,#RPC_C_IMP_LEVEL_IDENTIFY,0,#EOAC_NONE,0)
If hres <> 0: MessageRequester("ERROR", "unable to call CoInitializeSecurity", #MB_OK): Goto cleanup: EndIf
hres=CoCreateInstance_(?CLSID_WbemLocator,0,#CLSCTX_INPROC_SERVER,?IID_IWbemLocator,@loc.IWbemLocator)
If hres <> 0: MessageRequester("ERROR", "unable to call CoCreateInstance", #MB_OK): Goto cleanup: EndIf
hres=loc\ConnectServer(ansi2bstr("root\cimv2"),0,0,0,0,0,0,@svc.IWbemServices)
If hres <> 0: MessageRequester("ERROR", "unable to call IWbemLocator::ConnectServer", #MB_OK): Goto cleanup: EndIf
hres=svc\QueryInterface(?IID_IUnknown,@pUnk.IUnknown)
hres=CoSetProxyBlanket_(svc,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE)
If hres <> 0: MessageRequester("ERROR", "unable to call CoSetProxyBlanket", #MB_OK): Goto cleanup: EndIf
hres=CoSetProxyBlanket_(pUnk,#RPC_C_AUTHN_WINNT,#RPC_C_AUTHZ_NONE,0,#RPC_C_AUTHN_LEVEL_CALL,#RPC_C_IMP_LEVEL_IMPERSONATE,0,#EOAC_NONE)
If hres <> 0: MessageRequester("ERROR", "unable to call CoSetProxyBlanket", #MB_OK): Goto cleanup: EndIf
pUnk\Release()
; CallData
k=CountString(WMICommand,#WMISeparator)
Dim wmitxt$(k)
For i=0 To k
wmitxt$(i) = StringField(WMICommand,i+1,#WMISeparator)
Next
hres=svc\ExecQuery(ansi2bstr("WQL"),ansi2bstr(wmitxt$(0)), #IFlags,0,@pEnumerator.IEnumWbemClassObject)
If hres <> 0: MessageRequester("ERROR", "unable to call IWbemServices::ExecQuery", #MB_OK): Goto cleanup: EndIf
hres=pEnumerator\reset()
Repeat
hres=pEnumerator\Next(#WBEM_INFINITE, 1, @pclsObj.IWbemClassObject, @uReturn)
For i=1 To k
mem=AllocateMemory(1000)
hres=pclsObj\get(ansi2bstr(wmitxt$(i)), 0, mem, 0, 0)
Type=PeekW(mem)
Select Type
Case 8
val.s=PeekS(bstr2string(PeekL(mem+8)))
Case 3
val.s=Str(PeekL(mem+8))
Default
val.s=""
EndSelect
If uReturn <> 0: wmi$=wmi$+wmitxt$(i)+" = "+val+Chr(10)+Chr(13): EndIf
FreeMemory(mem)
Next
Until uReturn = 0
; Cleanup
cleanup:
svc\Release()
loc\Release()
pEnumerator\Release()
pclsObj\Release()
CoUninitialize_()
ProcedureReturn wmi$
EndProcedure
;{- WMI DATASECTION
DataSection
CLSID_WbemLocator:
Data.l $4590F811
Data.w $1D3A, $11D0
Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24
IID_IWbemLocator:
;dc12a687-737f-11cf-884d-00aa004b2e24
Data.l $DC12A687
Data.w $737F, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
IID_IUnknown:
Data.l $00000000
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
EndDataSection
;}
MessageRequester("WMI",WMI("SELECT * FROM Win32_LogicalDisk,DeviceID,Description,VolumeName"))
Last edited by RASHAD on Sun Jan 17, 2010 6:45 am, edited 1 time in total.
Egypt my love
Re: Drive/Volume Label
Very simple one
Code: Select all
For i = 65 To 90
VolumeName$ = Space(14)
Str$ = Space(32)
CDPath$ = Chr(i)+":\"
DriveType = GetDriveType_(CDPath$)
If DriveType = #DRIVE_CDROM Or DriveType = #DRIVE_FIXED
Debug CDPath$
GetVolumeInformation_(CDPath$,@VolumeName$,Len(VolumeName$),0,0,0,@Str$,Len(Str$))
Debug VolumeName$
EndIf
Next
Egypt my love
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Re: Drive/Volume Label
Thank you, but I already know how to obtain the volume name, I was now trying to get the label as specified
in registry if specified in registry. But thanks to Ts-Softs script I was able to obtain the GUID's to obtain the label.
If a drive contains an autorun.inf, the label could be specified in there. Or when a label is manually modified through
Rename in the drive's contextmenu in My Computer, also the label will be diffirent from the Volume Name. These
labels are saved in Registry when the drive connects and autorun.inf is read, or when the label is renamed in my computer.
Thanks for all the help, I'll try to get the custom label from registry now
in registry if specified in registry. But thanks to Ts-Softs script I was able to obtain the GUID's to obtain the label.
If a drive contains an autorun.inf, the label could be specified in there. Or when a label is manually modified through
Rename in the drive's contextmenu in My Computer, also the label will be diffirent from the Volume Name. These
labels are saved in Registry when the drive connects and autorun.inf is read, or when the label is renamed in my computer.
Thanks for all the help, I'll try to get the custom label from registry now

Re: Drive/Volume Label
@Crusiatus Black
Check using the second code
Change the volume label using any method
Run the code it will give you the new Label
Or may be I am missing something
Check using the second code
Change the volume label using any method
Run the code it will give you the new Label
Or may be I am missing something
Egypt my love
Re: Drive/Volume Label
You can use srod's COMate to get a bunch of info about drives through WMI using the different classes, for example using a combination of the the Win32_Volume class and some registry reads you can get this info: (I just threw in a wmi based registry read here from some testing stuff I was working on but you can use any registry read routine or procedure or library function)
Other WMI classes that might help you are Win32_LogicalDisk, Scripting.FileSystemObject, Win32_DiskDrive, Win32_CDROMDrive, or for network use there is the Win32_MappedLogicalDisk class too.
Code: Select all
XIncludeFile "COMatePLUS.pbi"
Procedure.s GetDWORDValue(hkey.i, strKeyPath.s, strValueName.s)
Define.COMateObject oReg
strComputer.s = "."
oReg = COMate_GetObject("winmgmts:\\.\root\default:StdRegProv", "")
oReg\Invoke("GetDWORDValue(" + Str(hkey) + ", '" + strKeyPath + "', '" + strValueName + "', " + Str(@dwValue) + " BYREF)")
dw_dword_value$ = Str(dwValue)
oReg\Release()
ProcedureReturn dw_dword_value$
EndProcedure
Procedure.s ConfigManager_ErrorCode(cm_ec.i)
Select cm_ec
Case 0
Error_Code_Type$ = "Device is working properly"
Case 1
Error_Code_Type$ = "Device is Not configured correctly."
Case 2
Error_Code_Type$ = "Windows cannot load the driver For this device."
Case 3
Error_Code_Type$ = "Driver For this device might be corrupted, Or the system may be low on memory or other resources."
Case 4
Error_Code_Type$ = "Device is Not working properly. One of its drivers or the registry might be corrupted."
Case 5
Error_Code_Type$ = "Driver For the device requires a resource that Windows cannot manage."
Case 6
Error_Code_Type$ = "Boot configuration For the device conflicts With other devices."
Case 7
Error_Code_Type$ = "Cannot filter."
Case 8
Error_Code_Type$ = "Driver loader For the device is missing."
Case 9
Error_Code_Type$ = "Device is Not working properly. The controlling firmware is incorrectly reporting the resources for the device."
Case 10
Error_Code_Type$ = "Device cannot start."
Case 11
Error_Code_Type$ = "Device failed."
Case 12
Error_Code_Type$ = "Device cannot find enough free resources To use."
Case 13
Error_Code_Type$ = "Windows cannot verify the device's resources."
Case 14
Error_Code_Type$ = "Device cannot work properly Until the computer is restarted."
Case 15
Error_Code_Type$ = "Device is Not working properly due To a possible re-Enumeration problem."
Case 16
Error_Code_Type$ = "Windows cannot identify all of the resources that the device uses."
Case 17
Error_Code_Type$ = "Device is requesting an unknown resource type."
Case 18
Error_Code_Type$ = "Device drivers must be reinstalled."
Case 19
Error_Code_Type$ = "Failure using the VxD loader."
Case 20
Error_Code_Type$ = "Registry might be corrupted."
Case 21
Error_Code_Type$ = "System failure. If changing the device driver is ineffective, see the hardware documentation. Windows is removing the device."
Case 22
Error_Code_Type$ = "Device is disabled."
Case 23
Error_Code_Type$ = "System failure. If changing the device driver is ineffective, see the hardware documentation."
Case 24
Error_Code_Type$ = "Device is Not present, Not working properly, Or does Not have all of its drivers installed."
Case 25
Error_Code_Type$ = "Windows is still setting up the device."
Case 26
Error_Code_Type$ = "Windows is still setting up the device."
Case 27
Error_Code_Type$ = "Device does Not have valid log configuration."
Case 28
Error_Code_Type$ = "Device drivers are Not installed."
Case 29
Error_Code_Type$ = "Device is disabled. The device firmware did Not provide the required resources."
Case 30
Error_Code_Type$ = "Device is using an IRQ resource that another device is using."
Case 31
Error_Code_Type$ = "Device is Not working properly. Windows cannot load the required device drivers."
EndSelect
ProcedureReturn Error_Code_Type$
EndProcedure
Procedure Volume_Info()
Define.COMateObject objWMIService, WinVOLInfo
colWinVOLInfo.COMateEnumObject
strComputer.s = "."
objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
colWinVOLInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_Volume')")
If colWinVOLInfo
WinVOLInfo = colWinVOLInfo\GetNextObject()
While WinVOLInfo
VVOL_SysName$ = WinVOLInfo\GetStringProperty("Name")
VVOL_Description$ = WinVOLInfo\GetStringProperty("Description")
VVOL_DriveLetter$ = WinVOLInfo\GetStringProperty("DriveLetter") + "\"
If FindString(VVOL_SysName$, "\\?\",1) <> 0
Raid_Part_note.i = #True
VVOL_DriveLetter_NotePart$ = "Probable RAID partition, no drive letter for this partition normal for RAID Arrays.)"
Else
Raid_Part_note.i = #False
EndIf
VVOL_DeviceID$ = WinVOLInfo\GetStringProperty("DeviceID")
VVOL_PNPDeviceID$ = WinVOLInfo\GetStringProperty("PNPDeviceID")
VVOL_FileSystem$ = WinVOLInfo\GetStringProperty("FileSystem")
VVOL_Label$ = WinVOLInfo\GetStringProperty("Label")
VVOL_FreeSpace$ = WinVOLInfo\GetStringProperty("FreeSpace")
VVOL_Capacity$ = WinVOLInfo\GetStringProperty("Capacity")
VVOL_MaximumFileNameLength$ = Str(WinVOLInfo\GetIntegerProperty("MaximumFileNameLength"))
VVOL_NumberOfBlocks$ = WinVOLInfo\GetStringProperty("NumberOfBlocks")
VVOL_BlockSize$ = WinVOLInfo\GetStringProperty("BlockSize")
VVOL_Purpose$ = WinVOLInfo\GetStringProperty("Purpose")
VVOL_ErrorDescription$ = WinVOLInfo\GetStringProperty("ErrorDescription")
Select WinVOLInfo\GetIntegerProperty("DriveType")
Case 0
VVOL_DriveType$ = "Unknown"
Case 1
VVOL_DriveType$ = "No Root Directory"
Case 2
VVOL_DriveType$ = "Removable Disk"
Case 3
VVOL_DriveType$ = "Local Disk"
Case 4
VVOL_DriveType$ = "Network Drive"
Case 5
VVOL_DriveType$ = "Compact Disk"
Case 6
VVOL_DriveType$ = "Ram Disk"
EndSelect
If WinVOLInfo\GetIntegerProperty("DirtyBitSet") = 0
VVOL_VolumeDirty$ = "False - Chkdsk will not run at the next restart."
Else
VVOL_VolumeDirty$ = "True - Chkdsk method is automatically run by the system at the next restart."
EndIf
If WinVOLInfo\GetIntegerProperty("SupportsDiskQuotas") = 0
VVOL_SupportsDiskQuotas$ = "This volume does not supports disk quotas."
Else
VVOL_SupportsDiskQuotas$ = "This volume supports disk quotas."
EndIf
If WinVOLInfo\GetIntegerProperty("QuotasEnabled") = 0
VVOL_QuotasEnabled$ = "Quota management is not enabled for this volume."
Else
VVOL_QuotasEnabled$ = "Quota management is enabled for this volume."
EndIf
If WinVOLInfo\GetIntegerProperty("Automount") = 0
VVOL_Automount$ = "False"
Else
VVOL_Automount$ = "True"
EndIf
If WinVOLInfo\GetIntegerProperty("IndexingEnabled") = 0
VVOL_IndexingEnabled$ = "False - Context Indexing is not enabled"
Else
VVOL_IndexingEnabled$ = "True - Context Indexing is enabled"
EndIf
VVOL_ConfigManagerErrorCode$ = ConfigManager_ErrorCode(WinVOLInfo\GetIntegerProperty("ConfigManagerErrorCode"))
rmv_str_1$ = RemoveString(VVOL_DeviceID$, "\\?\", #PB_String_NoCase, 1)
rmv_str_2$ = RemoveString(rmv_str_1$, "\", #PB_String_NoCase, 1)
HKEY_Drive$ = "SOFTWARE\Microsoft\Dfrg\Statistics\" + rmv_str_2$
TotalUsedClusters$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "TotalUsedClusters")
TotalClusters$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "TotalClusters")
BytesPerCluster$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "BytesPerCluster")
FragmentedSpace$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FragmentedSpace")
AvgFragmentsPerFile$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "AvgFragmentsPerFile")
MovableFiles$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "MovableFiles")
UnmovableFiles$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "UnmovableFiles")
FragmentedFiles$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FragmentedFiles")
DirectoryCount$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "DirectoryCount")
FragmentedDirectories$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FragmentedDirectories")
FreeSpaceCount$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FreeSpaceCount")
AvgFreeSpaceSize$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "AvgFreeSpaceSize")
LargestFreeSpaceSize$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "LargestFreeSpaceSize")
TotalMFTRecords$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "TotalMFTRecords")
InUseMFTRecords$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "InUseMFTRecords")
Debug VVOL_SysName$ + " Name = " + " " + VVOL_Name$
Debug VVOL_SysName$ + " Drive Letter Path = " + " " + VVOL_DriveLetter$
Debug VVOL_SysName$ + " Label= " + " " + VVOL_Label$
Debug VVOL_SysName$ + " Description = " + " " + VVOL_Description$
Debug VVOL_SysName$ + " Drive Type = " + " " + VVOL_DriveType$
Debug VVOL_SysName$ + " Purpose = " + " " + VVOL_Purpose$
Debug VVOL_SysName$ + " Auto Mount = " + " " + VVOL_Automount$
Debug VVOL_SysName$ + " Device ID = " + " " + VVOL_DeviceID$
Debug VVOL_SysName$ + " PNP Device ID = " + " " + VVOL_PNPDeviceID$
Debug VVOL_SysName$ + " File System = " + " " + VVOL_FileSystem$
Debug VVOL_SysName$ + " Capacity = " + " " + VVOL_Capacity$ + " Bytes"
Debug VVOL_SysName$ + " Free Space = " + " " + VVOL_FreeSpace$ + " Bytes"
Debug VVOL_SysName$ + " Number Of Blocks = " + " " + VVOL_NumberOfBlocks$
Debug VVOL_SysName$ + " Block Size = " + " " + VVOL_BlockSize$
Debug VVOL_SysName$ + " Volume Dirty = " + " " + VVOL_VolumeDirty$
Debug VVOL_SysName$ + " Supports Disk Quotas = " + " " + VVOL_SupportsDiskQuotas$
Debug VVOL_SysName$ + " Quotas Enabled = " + " " + VVOL_QuotasEnabled$
Debug VVOL_SysName$ + " Indexing Enabled = " + " " + VVOL_IndexingEnabled$
Debug VVOL_SysName$ + " Maximum File Name Length = " + " " + VVOL_MaximumFileNameLength$
If VVOL_Status$ = "Pred Fail"
Debug VVOL_SysName$ + " WARNING !" + " THIS DEVICE IS PREDICTING FAILURE IN THE NEAR FUTURE!!! RECOMMEND IMMEDIATE BACK UP !!!"
EndIf
Debug VVOL_SysName$ + " Error Code Info = " + " " + VVOL_ConfigManagerErrorCode$
Debug VVOL_SysName$ + " Error Description = " + " " + VVOL_ErrorDescription$
Debug VVOL_SysName$ + " Defrag Stat: Total Used Clusters = " + " " + TotalUsedClusters$
Debug VVOL_SysName$ + " Defrag Stat: Total Clusters = " + " " + TotalClusters$
Debug VVOL_SysName$ + " Defrag Stat: Bytes Per Cluster = " + " " + BytesPerCluster$
Debug VVOL_SysName$ + " Defrag Stat: Fragmented Space = " + " " + FragmentedSpace$
Debug VVOL_SysName$ + " Defrag Stat: Movable Files = " + " " + MovableFiles$
Debug VVOL_SysName$ + " Defrag Stat: Unmovable Files = " + " " + UnmovableFiles$
Debug VVOL_SysName$ + " Defrag Stat: Fragmented Files = " + " " + FragmentedFiles$
Debug VVOL_SysName$ + " Defrag Stat: Avg Fragments Per File = " + " " + AvgFragmentsPerFile$
Debug VVOL_SysName$ + " Defrag Stat: Directory Count = " + " " + DirectoryCount$
Debug VVOL_SysName$ + " Defrag Stat: Fragmented Directories = " + " " + FragmentedDirectories$
Debug VVOL_SysName$ + " Defrag Stat: Free Space Count = " + " " + FreeSpaceCount$
Debug VVOL_SysName$ + " Defrag Stat: Avg Free Space Size = " + " " + AvgFreeSpaceSize$
Debug VVOL_SysName$ + " Defrag Stat: Largest Free Space Size = " + " " + LargestFreeSpaceSize$
Debug VVOL_SysName$ + " Defrag Stat: Total MFT Records = " + " " + TotalMFTRecords$
Debug VVOL_SysName$ + " Defrag Stat: In Use MFT Records = " + " " + InUseMFTRecords$
If Raid_Part_note = #True
Debug "ADDITIONAL INFORMATION FOR THIS ENTRY = " + " " + VVOL_DriveLetter_NotePart$
EndIf
Debug "============================="
WinVOLInfo\Release()
WinVOLInfo = colWinVOLInfo\GetNextObject()
Wend
colWinVOLInfo\Release()
EndIf
objWMIService\Release()
Else
MessageRequester("Error", "WinVOLInfo")
EndIf
EndProcedure
Volume_Info()
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Re: Drive/Volume Label
That will only return the VolumeNameRASHAD wrote:@Crusiatus Black
Check using the second code
Change the volume label using any method
Run the code it will give you the new Label
Or may be I am missing something

listed as Portable HDD 500 GiB < label
Why didn't M$ just stick to VolumeName?

Thank you,SFSxOI wrote:You can use srod's COMate to get a bunch of info about drives through WMI using the different classes, for example using a combination of the the Win32_Volume class and some registry reads you can get this info: (I just threw in a wmi based registry read here from some testing stuff I was working on but you can use any registry read routine or procedure or library function)
Other WMI classes that might help you are Win32_LogicalDisk, Scripting.FileSystemObject, Win32_DiskDrive, Win32_CDROMDrive, or for network use there is the Win32_MappedLogicalDisk class too.Code: Select all
XIncludeFile "COMatePLUS.pbi" Procedure.s GetDWORDValue(hkey.i, strKeyPath.s, strValueName.s) Define.COMateObject oReg strComputer.s = "." oReg = COMate_GetObject("winmgmts:\\.\root\default:StdRegProv", "") oReg\Invoke("GetDWORDValue(" + Str(hkey) + ", '" + strKeyPath + "', '" + strValueName + "', " + Str(@dwValue) + " BYREF)") dw_dword_value$ = Str(dwValue) oReg\Release() ProcedureReturn dw_dword_value$ EndProcedure Procedure.s ConfigManager_ErrorCode(cm_ec.i) Select cm_ec Case 0 Error_Code_Type$ = "Device is working properly" Case 1 Error_Code_Type$ = "Device is Not configured correctly." Case 2 Error_Code_Type$ = "Windows cannot load the driver For this device." Case 3 Error_Code_Type$ = "Driver For this device might be corrupted, Or the system may be low on memory or other resources." Case 4 Error_Code_Type$ = "Device is Not working properly. One of its drivers or the registry might be corrupted." Case 5 Error_Code_Type$ = "Driver For the device requires a resource that Windows cannot manage." Case 6 Error_Code_Type$ = "Boot configuration For the device conflicts With other devices." Case 7 Error_Code_Type$ = "Cannot filter." Case 8 Error_Code_Type$ = "Driver loader For the device is missing." Case 9 Error_Code_Type$ = "Device is Not working properly. The controlling firmware is incorrectly reporting the resources for the device." Case 10 Error_Code_Type$ = "Device cannot start." Case 11 Error_Code_Type$ = "Device failed." Case 12 Error_Code_Type$ = "Device cannot find enough free resources To use." Case 13 Error_Code_Type$ = "Windows cannot verify the device's resources." Case 14 Error_Code_Type$ = "Device cannot work properly Until the computer is restarted." Case 15 Error_Code_Type$ = "Device is Not working properly due To a possible re-Enumeration problem." Case 16 Error_Code_Type$ = "Windows cannot identify all of the resources that the device uses." Case 17 Error_Code_Type$ = "Device is requesting an unknown resource type." Case 18 Error_Code_Type$ = "Device drivers must be reinstalled." Case 19 Error_Code_Type$ = "Failure using the VxD loader." Case 20 Error_Code_Type$ = "Registry might be corrupted." Case 21 Error_Code_Type$ = "System failure. If changing the device driver is ineffective, see the hardware documentation. Windows is removing the device." Case 22 Error_Code_Type$ = "Device is disabled." Case 23 Error_Code_Type$ = "System failure. If changing the device driver is ineffective, see the hardware documentation." Case 24 Error_Code_Type$ = "Device is Not present, Not working properly, Or does Not have all of its drivers installed." Case 25 Error_Code_Type$ = "Windows is still setting up the device." Case 26 Error_Code_Type$ = "Windows is still setting up the device." Case 27 Error_Code_Type$ = "Device does Not have valid log configuration." Case 28 Error_Code_Type$ = "Device drivers are Not installed." Case 29 Error_Code_Type$ = "Device is disabled. The device firmware did Not provide the required resources." Case 30 Error_Code_Type$ = "Device is using an IRQ resource that another device is using." Case 31 Error_Code_Type$ = "Device is Not working properly. Windows cannot load the required device drivers." EndSelect ProcedureReturn Error_Code_Type$ EndProcedure Procedure Volume_Info() Define.COMateObject objWMIService, WinVOLInfo colWinVOLInfo.COMateEnumObject strComputer.s = "." objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "") If objWMIService colWinVOLInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_Volume')") If colWinVOLInfo WinVOLInfo = colWinVOLInfo\GetNextObject() While WinVOLInfo VVOL_SysName$ = WinVOLInfo\GetStringProperty("Name") VVOL_Description$ = WinVOLInfo\GetStringProperty("Description") VVOL_DriveLetter$ = WinVOLInfo\GetStringProperty("DriveLetter") + "\" If FindString(VVOL_SysName$, "\\?\",1) <> 0 Raid_Part_note.i = #True VVOL_DriveLetter_NotePart$ = "Probable RAID partition, no drive letter for this partition normal for RAID Arrays.)" Else Raid_Part_note.i = #False EndIf VVOL_DeviceID$ = WinVOLInfo\GetStringProperty("DeviceID") VVOL_PNPDeviceID$ = WinVOLInfo\GetStringProperty("PNPDeviceID") VVOL_FileSystem$ = WinVOLInfo\GetStringProperty("FileSystem") VVOL_Label$ = WinVOLInfo\GetStringProperty("Label") VVOL_FreeSpace$ = WinVOLInfo\GetStringProperty("FreeSpace") VVOL_Capacity$ = WinVOLInfo\GetStringProperty("Capacity") VVOL_MaximumFileNameLength$ = Str(WinVOLInfo\GetIntegerProperty("MaximumFileNameLength")) VVOL_NumberOfBlocks$ = WinVOLInfo\GetStringProperty("NumberOfBlocks") VVOL_BlockSize$ = WinVOLInfo\GetStringProperty("BlockSize") VVOL_Purpose$ = WinVOLInfo\GetStringProperty("Purpose") VVOL_ErrorDescription$ = WinVOLInfo\GetStringProperty("ErrorDescription") Select WinVOLInfo\GetIntegerProperty("DriveType") Case 0 VVOL_DriveType$ = "Unknown" Case 1 VVOL_DriveType$ = "No Root Directory" Case 2 VVOL_DriveType$ = "Removable Disk" Case 3 VVOL_DriveType$ = "Local Disk" Case 4 VVOL_DriveType$ = "Network Drive" Case 5 VVOL_DriveType$ = "Compact Disk" Case 6 VVOL_DriveType$ = "Ram Disk" EndSelect If WinVOLInfo\GetIntegerProperty("DirtyBitSet") = 0 VVOL_VolumeDirty$ = "False - Chkdsk will not run at the next restart." Else VVOL_VolumeDirty$ = "True - Chkdsk method is automatically run by the system at the next restart." EndIf If WinVOLInfo\GetIntegerProperty("SupportsDiskQuotas") = 0 VVOL_SupportsDiskQuotas$ = "This volume does not supports disk quotas." Else VVOL_SupportsDiskQuotas$ = "This volume supports disk quotas." EndIf If WinVOLInfo\GetIntegerProperty("QuotasEnabled") = 0 VVOL_QuotasEnabled$ = "Quota management is not enabled for this volume." Else VVOL_QuotasEnabled$ = "Quota management is enabled for this volume." EndIf If WinVOLInfo\GetIntegerProperty("Automount") = 0 VVOL_Automount$ = "False" Else VVOL_Automount$ = "True" EndIf If WinVOLInfo\GetIntegerProperty("IndexingEnabled") = 0 VVOL_IndexingEnabled$ = "False - Context Indexing is not enabled" Else VVOL_IndexingEnabled$ = "True - Context Indexing is enabled" EndIf VVOL_ConfigManagerErrorCode$ = ConfigManager_ErrorCode(WinVOLInfo\GetIntegerProperty("ConfigManagerErrorCode")) rmv_str_1$ = RemoveString(VVOL_DeviceID$, "\\?\", #PB_String_NoCase, 1) rmv_str_2$ = RemoveString(rmv_str_1$, "\", #PB_String_NoCase, 1) HKEY_Drive$ = "SOFTWARE\Microsoft\Dfrg\Statistics\" + rmv_str_2$ TotalUsedClusters$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "TotalUsedClusters") TotalClusters$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "TotalClusters") BytesPerCluster$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "BytesPerCluster") FragmentedSpace$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FragmentedSpace") AvgFragmentsPerFile$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "AvgFragmentsPerFile") MovableFiles$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "MovableFiles") UnmovableFiles$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "UnmovableFiles") FragmentedFiles$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FragmentedFiles") DirectoryCount$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "DirectoryCount") FragmentedDirectories$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FragmentedDirectories") FreeSpaceCount$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "FreeSpaceCount") AvgFreeSpaceSize$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "AvgFreeSpaceSize") LargestFreeSpaceSize$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "LargestFreeSpaceSize") TotalMFTRecords$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "TotalMFTRecords") InUseMFTRecords$ = GetDWORDValue(#HKEY_LOCAL_MACHINE, HKEY_Drive$, "InUseMFTRecords") Debug VVOL_SysName$ + " Name = " + " " + VVOL_Name$ Debug VVOL_SysName$ + " Drive Letter Path = " + " " + VVOL_DriveLetter$ Debug VVOL_SysName$ + " Label= " + " " + VVOL_Label$ Debug VVOL_SysName$ + " Description = " + " " + VVOL_Description$ Debug VVOL_SysName$ + " Drive Type = " + " " + VVOL_DriveType$ Debug VVOL_SysName$ + " Purpose = " + " " + VVOL_Purpose$ Debug VVOL_SysName$ + " Auto Mount = " + " " + VVOL_Automount$ Debug VVOL_SysName$ + " Device ID = " + " " + VVOL_DeviceID$ Debug VVOL_SysName$ + " PNP Device ID = " + " " + VVOL_PNPDeviceID$ Debug VVOL_SysName$ + " File System = " + " " + VVOL_FileSystem$ Debug VVOL_SysName$ + " Capacity = " + " " + VVOL_Capacity$ + " Bytes" Debug VVOL_SysName$ + " Free Space = " + " " + VVOL_FreeSpace$ + " Bytes" Debug VVOL_SysName$ + " Number Of Blocks = " + " " + VVOL_NumberOfBlocks$ Debug VVOL_SysName$ + " Block Size = " + " " + VVOL_BlockSize$ Debug VVOL_SysName$ + " Volume Dirty = " + " " + VVOL_VolumeDirty$ Debug VVOL_SysName$ + " Supports Disk Quotas = " + " " + VVOL_SupportsDiskQuotas$ Debug VVOL_SysName$ + " Quotas Enabled = " + " " + VVOL_QuotasEnabled$ Debug VVOL_SysName$ + " Indexing Enabled = " + " " + VVOL_IndexingEnabled$ Debug VVOL_SysName$ + " Maximum File Name Length = " + " " + VVOL_MaximumFileNameLength$ If VVOL_Status$ = "Pred Fail" Debug VVOL_SysName$ + " WARNING !" + " THIS DEVICE IS PREDICTING FAILURE IN THE NEAR FUTURE!!! RECOMMEND IMMEDIATE BACK UP !!!" EndIf Debug VVOL_SysName$ + " Error Code Info = " + " " + VVOL_ConfigManagerErrorCode$ Debug VVOL_SysName$ + " Error Description = " + " " + VVOL_ErrorDescription$ Debug VVOL_SysName$ + " Defrag Stat: Total Used Clusters = " + " " + TotalUsedClusters$ Debug VVOL_SysName$ + " Defrag Stat: Total Clusters = " + " " + TotalClusters$ Debug VVOL_SysName$ + " Defrag Stat: Bytes Per Cluster = " + " " + BytesPerCluster$ Debug VVOL_SysName$ + " Defrag Stat: Fragmented Space = " + " " + FragmentedSpace$ Debug VVOL_SysName$ + " Defrag Stat: Movable Files = " + " " + MovableFiles$ Debug VVOL_SysName$ + " Defrag Stat: Unmovable Files = " + " " + UnmovableFiles$ Debug VVOL_SysName$ + " Defrag Stat: Fragmented Files = " + " " + FragmentedFiles$ Debug VVOL_SysName$ + " Defrag Stat: Avg Fragments Per File = " + " " + AvgFragmentsPerFile$ Debug VVOL_SysName$ + " Defrag Stat: Directory Count = " + " " + DirectoryCount$ Debug VVOL_SysName$ + " Defrag Stat: Fragmented Directories = " + " " + FragmentedDirectories$ Debug VVOL_SysName$ + " Defrag Stat: Free Space Count = " + " " + FreeSpaceCount$ Debug VVOL_SysName$ + " Defrag Stat: Avg Free Space Size = " + " " + AvgFreeSpaceSize$ Debug VVOL_SysName$ + " Defrag Stat: Largest Free Space Size = " + " " + LargestFreeSpaceSize$ Debug VVOL_SysName$ + " Defrag Stat: Total MFT Records = " + " " + TotalMFTRecords$ Debug VVOL_SysName$ + " Defrag Stat: In Use MFT Records = " + " " + InUseMFTRecords$ If Raid_Part_note = #True Debug "ADDITIONAL INFORMATION FOR THIS ENTRY = " + " " + VVOL_DriveLetter_NotePart$ EndIf Debug "=============================" WinVOLInfo\Release() WinVOLInfo = colWinVOLInfo\GetNextObject() Wend colWinVOLInfo\Release() EndIf objWMIService\Release() Else MessageRequester("Error", "WinVOLInfo") EndIf EndProcedure Volume_Info()
that helps me to obtain the Drive's label and volumename,
I have been looking through my registry and found the GUID paths of the drives...
All drives, there's even a MRU kind of list for every disc that was ever inserted in your CDROM drive which contained an autorun...
Re: Drive/Volume Label
@Crusiatus Black
Just for curiosity check using the next piece
Just for curiosity check using the next piece
Code: Select all
For i = 65 To 90
VolumeName$ = Space(14)
Str$ = Space(32)
CDPath$ = Chr(i)+":\"
DriveType = GetDriveType_(CDPath$)
If DriveType <> 1
Debug CDPath$
GetVolumeInformation_(CDPath$,@VolumeName$,Len(VolumeName$),0,0,0,@Str$,Len(Str$))
Debug VolumeName$
EndIf
Next
Egypt my love
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Re: Drive/Volume Label
OkayRASHAD wrote:@Crusiatus Black
Just for curiosity check using the next piece
Code: Select all
For i = 65 To 90 VolumeName$ = Space(14) Str$ = Space(32) CDPath$ = Chr(i)+":\" DriveType = GetDriveType_(CDPath$) If DriveType <> 1 Debug CDPath$ GetVolumeInformation_(CDPath$,@VolumeName$,Len(VolumeName$),0,0,0,@Str$,Len(Str$)) Debug VolumeName$ EndIf Next

And in My Computer, G:\ is displayed as Portable HDD 500 GiBdebugger wrote: C:\
D:\
LOKAAL D
E:\
G:\
PortableHDD500
Z:\
Also C is usually listed as Lokaal Station C, Z is listed as Shared @ Server, so I'd like to obtain those labels.
I thought there would be some dandy winapi for that aswell hehe.
Re: Drive/Volume Label
Thank you very much
Yes it may be, I am running Win 7 x64 PB 4.4 x86 x64
I will check with XP and Vista later it can be the size of the variables and the unicode matters
Again thank you I appreciate your quick response
Yes it may be, I am running Win 7 x64 PB 4.4 x86 x64
I will check with XP and Vista later it can be the size of the variables and the unicode matters
Again thank you I appreciate your quick response
Egypt my love
- Crusiatus Black
- Enthusiast
- Posts: 389
- Joined: Mon May 12, 2008 1:25 pm
- Location: The Netherlands
- Contact:
Re: Drive/Volume Label
No problemRASHAD wrote:Thank you very much
Yes it may be, I am running Win 7 x64 PB 4.4 x86 x64
I will check with XP and Vista later it can be the size of the variables and the unicode matters
Again thank you I appreciate your quick response


Anyhow, I doubt it could be a lpsize matter or unicode matter, because it does return a string,
but the volumename, and not the label as displayed in My Computer.
I think the display-label can only be obtained from registry using the corresponding GUID path.