Announcement

Collapse
No announcement yet.

GetVolumeInformation Fails on D

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetVolumeInformation Fails on D

    I'm using this function in a for next loop using 65 through 90 as drives.
    I test if they are available (See Enum Drive post) and it returns the drive type etc and validates it does exist.
    I then run the function to determine what KIND of drive it is, fixed disk or CDRom, removeable etc...

    Life is good, C: returns the proper information from This function, D: does not and it is a fixed disk on my Win2k server...

    Code:
    'In PBMain
    
    Local VolumeSerial  As String
    Local VolumeLabel   As String
    
    Local lResult       As Long
    Local lLoop         As Long
    
    
    WriteCGI  "<TR><TD>Drives Available:</TD><TD>" & $CRLF
    For lLoop = 65 To 90
        If IsTrue DriveIsAvailable(ByVal Chr$(lLoop)) Then
            VolumeSerial = "":VolumeLabel = ""
            lResult = CCSGetVolumeInformation(Chr$(lLoop) + ":",VolumeSerial,VolumeLabel)
            WriteCGI  "Drive " & Chr$(lLoop) & ":<BR>" & $CRLF
            WriteCGI  "Volume Label: " & VolumeLabel & "<br>" & $CRLF
            WriteCGI  "Volume Serial No: " & VolumeSerial & "<BR>" & $CRLF
            WriteCGI  "Drive Type: <B>" & DriveType(Chr$(lLoop) & ":") & "</B><HR>" & $CRLF
        End If
    Next
    WriteCGI "</TD></TR>"  'End drive enumeration TD
     
    
    
    '------------------------------------------------------------
    Function CCSGetVolumeInformation(Drive As String,SerialNo As String,VolLabel As String) As Long
    Local HWord As Word
    Local LWord As Word
    Local lpVolumeNameBuffer As Asciiz * 255
    Local lpVolumeSerialNumber As Long
    Local lpMaximumComponentLength As Long
    Local lpFileSystemFlags As Long
    Local FileSysBuffer As Asciiz * 255
    Local lpDrive       As Asciiz * 3
    lpDrive = Drive
    
    If GetVolumeInformation (lpDrive, lpVolumeNameBuffer, SizeOf(lpVolumeNameBuffer)-1, lpVolumeSerialNumber , lpMaximumComponentLength, _
    lpFileSystemFlags , FilesysBuffer, SizeOf(FilesysBuffer)) <> 0 Then
        HWord = HiWrd(lpVolumeSerialNumber)
        LWord = LoWrd(lpVolumeSerialNumber)
        SerialNo = Right$("0000000"+Hex$(HWord), 4) + "-" + Right$("0000000"+Hex$(LWord), 4)
        VolLabel = lpVolumeNameBuffer
        Function = %TRUE
    Else
        Function = %FALSE
    End If
    
    End Function  
    
    '------------------------------------------------------------------------------------------------------------------------
    Function DriveIsAvailable(ByVal Drive As String) As Long
    Local StringVar As String
    Local LongVar As Long
    Local LongVar2 As Long
    Local lresult  As Long
    Local lptr     As Long
    
    Drive = Left$(Drive,1) 'Just the D, not the :
    LongVar = GetLogicalDrives
    For LongVar2 = 0 To 25
        StringVar = StringVar + Ltrim$(Str$(Bit(LongVar, LongVar2),1))
    Next
    '65 is A
    lptr = Asc(Drive) - 64
    '1011110000000000
    'ABCDEFGHIJKLMNOP etc
    Function = Val(Mid$(StringVar,lptr,1))
    End Function
    '------------------------------------------------------------------------------------------------------------------------
    Function DriveType(Drive As String) As String
    Local sDrive    As Asciiz * 255
    Local lresult   As Long
    %DRIVE_TYPE_UNDTERMINED = 0
    %DRIVE_ROOT_NOT_EXIST = 1
    %DRIVE_REMOVABLE = 2
    %DRIVE_FIXED = 3
    %DRIVE_REMOTE = 4
    %DRIVE_CDROM = 5
    %DRIVE_RAMDISK = 6
    
    sDrive = Drive
    lResult = GetDriveType(sDrive)
    Select Case lResult
        Case %DRIVE_TYPE_UNDTERMINED
            Function = "Undetermined"
        Case %DRIVE_ROOT_NOT_EXIST
            Function = "Root does not exist"
        Case %DRIVE_CDROM
            Function = "CD-ROM"
        Case %DRIVE_FIXED
            Function = "Fixed Disk"
        Case %DRIVE_RAMDISK
            Function = "RAM Disk"
        Case %DRIVE_REMOTE
            Function = "Remote Drive"
        Case %DRIVE_REMOVABLE
            Function = "Removable Drive"
    End Select
    End Function
    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    [This message has been edited by Scott Turchin (edited December 03, 2000).]
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    And this is what the output of that above looks like:

    Code:
    Drives Available: Drive A:
    Volume Label: 
    Volume Serial No: 
    Drive Type: Removable Drive
    --------------------------------------------------------------------------------
     Drive C:
    Volume Label: TNG
    Volume Serial No: A8A7-FE0A
    Drive Type: Fixed Disk
    --------------------------------------------------------------------------------
     Drive D:
    Volume Label: 
    Volume Serial No: 
    Drive Type: Fixed Disk
    --------------------------------------------------------------------------------
     Drive E:
    Volume Label: 
    Volume Serial No: 
    Drive Type: Removable Drive
    --------------------------------------------------------------------------------
     Drive F:
    Volume Label: 
    Volume Serial No: 
    Drive Type: CD-ROM
    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      According to the doc's, GetVolumeInformation() expects the 1st parameter to point to the ROOT directory, ie, "D:\". Try adding a backslash...


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Yup, that was it, that and I had to change the sDrive as Asciiz * 3 to 4 for the "\" to fit in there


        Thanks!
        This is most awesome, I'll repost the entire source for TNGSysinfo in the Source code forum (CGI Based of course)..


        Scott


        ------------------
        Scott
        mailto:[email protected][email protected]</A>
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment

        Working...
        X