Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get drive space does not work on specific drive
Message
From
03/05/2012 15:15:30
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Get drive space does not work on specific drive
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01543132
Message ID:
01543132
Views:
81
This is a method I have in my framework and this usually work to return some info about the drive:
        ' Get the information on a drive
        Public Function GetDriveInformation() As Boolean
            Dim lcProviderName As String = ""
            Dim lcSQL As String = ""
            Dim llSuccess As Boolean = False
            Dim loQuery As SelectQuery
            Dim loManagementObject As ManagementObject
            Dim loSearcher As ManagementObjectSearcher

            ' Reset the values
            cVolumeName = ""
            cVolumeSerialNumber = ""
            nFreeSpace = 0

            ' Initialization
            lcProviderName = cProviderName

            ' Make it compatible
            lcProviderName = oApp.StrTran(lcProviderName, "\", "\\")

            ' Adjust SQL as per type of drive
            Select Case nType

                ' Local drive
                Case 1
                    lcSQL = "SELECT FreeSpace,QuotasDisabled,VolumeName,VolumeSerialNumber " + _
                     "FROM Win32_LogicalDisk WHERE DeviceID=""" + lcProviderName + """"

                    ' UNC drive
                Case 2
                    lcSQL = "SELECT FreeSpace,QuotasDisabled,VolumeName,VolumeSerialNumber " + _
                     "FROM Win32_LogicalDisk WHERE ProviderName=""" + lcProviderName + """"

            End Select

            ' In Windows Service, this doesn't work
            Try
                loQuery = New SelectQuery(lcSQL)
                loSearcher = New ManagementObjectSearcher(loQuery)

                For Each loManagementObject In loSearcher.Get()

                    ' Free disk space is irrelevant if per user quota's are enabled
                    If loManagementObject("QuotasDisabled").ToString() <> "true" Then
                        cVolumeName = loManagementObject("VolumeName")
                        cVolumeSerialNumber = loManagementObject("VolumeSerialNumber")
                        nFreeSpace = loManagementObject("Freespace")
                    End If

                Next

                llSuccess = True

            Catch loError As Exception
                cMessage = loError.Message
            End Try

            Return llSuccess
        End Function
The actual command that is being executed is:

SELECT FreeSpace,QuotasDisabled,VolumeName,VolumeSerialNumber FROM Win32_LogicalDisk WHERE ProviderName="\\\\10.10.10.10.\\f$"

The IP is not valid but this is just to show you an example. So, this is a UNC approach.

On that particular drive, it will not find anything. Thus, it will not go into the For Each loop. In this case, it should return one entry. Because I use a WHERE clause to specify the exact UNC location, this should return one entry. Then, in the For Each loop, it should give me the volume name, volume serial numnber and free space.

Does anyone know why this doesn't return anything?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform