Drive/Volume Label

Just starting out? Need help? Post your questions and find answers here.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Drive/Volume Label

Post by SFSxOI »

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)

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()

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.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Drive/Volume Label

Post by Crusiatus Black »

RASHAD 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
That will only return the VolumeName :) If I use this on my external harddrive, it returns PortableHDD500 while in my computer it's
listed as Portable HDD 500 GiB < label
Why didn't M$ just stick to VolumeName? :P
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)

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()

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.
Thank you,
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...
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Drive/Volume Label

Post by RASHAD »

@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
Egypt my love
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Drive/Volume Label

Post by Crusiatus Black »

RASHAD 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
Okay :) But like I said, it does not return the name as displayed. (WinXP Pro SP3, maybe that matters?)
debugger wrote: C:\

D:\
LOKAAL D
E:\

G:\
PortableHDD500
Z:\
And in My Computer, G:\ is displayed as Portable HDD 500 GiB

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.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Drive/Volume Label

Post by RASHAD »

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
Egypt my love
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Drive/Volume Label

Post by Crusiatus Black »

RASHAD 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
No problem :) Thanks for helping :)

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.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Drive/Volume Label

Post by SFSxOI »

In windows 7 you can also get the volume lables from the registry at : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\VolumeInfoCache
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Drive/Volume Label

Post by Crusiatus Black »

SFSxOI wrote:In windows 7 you can also get the volume lables from the registry at : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\VolumeInfoCache
Thanks :)

In Windows XP, I'm able to obtain the label through a GUID path, could you confirm if this path
exists in Windows 7?

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\
This contains a list of drive GUID's currently or once connected to the system.

*Edit, and if in some of the GUID Keys there is a Reg_SZ value named _LabelFromReg or a subkey named _Autorun?
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Drive/Volume Label

Post by Crusiatus Black »

If that key exists in windows 7 (and I believe it does, because kernel32.dll > GetVolumeNameForVolumeMountPoint exists in Win7 aswell)
then obtaining the label will be easy from registry, here's a function to get the GUID or VolumePath for a specific drive.

A little by the way, over here a DRIVE_REMOTE does not have a GUID nor VolumePath.

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  
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Drive/Volume Label

Post by SFSxOI »

Yes, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2 does exist in Windows 7, however, it does not contain any volume lables.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Drive/Volume Label

Post by Crusiatus Black »

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.
Thanks,


Correct, it contains GUID's, for example: {0b2d57c1-5a99-11dd-b560-806d6172696f} and if that drive (because that GUID represents a drive)
has a custom label specified through an autorun.inf/ini it contains the subkey \_Autorun\DefaultLabel or through renaming it in My Computer it contains REG_SZ Key _LabelFromReg.

MountPoints2 is the registry entry for mounting drives I suppose, so the labels and default icons are specified there.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Drive/Volume Label

Post by Crusiatus Black »

Here is some code to get the a certain drive's label if it exists.

First it checks for _LabelFromReg, the label edited through windows.
Then it checks for _Autorun\DefaultLabel, if this value is not empty,
it will overwrite the previous found label, pretty much the same what Explorer.exe does.

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 
You should decomment the next two lines if you do not wish to overwrite:

Code: Select all

;If Not Trim(szRetVal)
and

Code: Select all

;EndIf
Now to obtain a drive's label, use the next code:

Code: Select all

szDriveLabel.s = GetLabelFromGUID(GetDriveGUIDPath("C:\", #True))
if the label is present, it will be stored in szDriveLabel :D

I found out that it doesn't work on DRIVE_REMOTE drives, because windows doesn't return the VolumePath of these drives.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
Post Reply