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:57:14
Al Doman (Online)
M3 Enterprises Inc.
North Vancouver, British Columbia, Canada
 
 
To
03/05/2012 15:15:30
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
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:
01543139
Views:
46
>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?

Maybe this: http://www.pcreview.co.uk/forums/win32_logicaldisk-not-working-properly-t1800148.html

There are some gotchas with administrative shares C$, F$ etc. Unless they are explicitly shared (which is rarely the case), I believe they are only accessible to local or domain admins. If the computer you're trying to access is Win7 (probably Server 2008 or Vista as well) there are additional restrictions on access to the root of a volume.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform