Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot used DriveInfo() on UNC drive
Message
From
01/11/2006 18:08:52
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/11/2006 12:47:28
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01166071
Message ID:
01166419
Views:
16
>>I was too surprised it fails with UNC paths. Documentation doesn't say that (only says it wouldn't work with deviceid but UNC should not be considered as a deviceid). Probably a bug or a feature:) Under the covers it might be calling System.Management.ManagementObject with a ManagementPath to win32_device.LogicalDisk. If that's the case then it'd fail where WBEM classes are not registered on remote computer. I expected that to map to win32 services like GetVolumeInformation, GetDiskFreeSpaceEx etc which do work with UNC paths.
>>Anyway I think this one and other GetFreeSpace code piece in C# was related. If so then you could use this:
>>
>>
>>Imports System.Runtime.InteropServices
>>
>>Module getdiskspacesample
>>
>>   Public Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
>>     Alias "GetDiskFreeSpaceExA" _
>>         (ByVal lpRootPathName As String, _
>>          ByRef lpFreeBytesAvailableToCaller As UInt64, _
>>          ByRef lpTotalNumberOfBytes As UInt64, _
>>          ByRef lpTotalNumberOfFreeBytes As UInt64) As Integer
>>
>>Sub Main()
>>
>>        Dim freeBytesToCaller As UInt64
>>        Dim totalNumberOfBytes As UInt64
>>        Dim totalNumberOfFreeBytes As UInt64
>>
>>        Dim rootPathName as string = "\\poseidon\c$"
>>
>>        GetDiskFreeSpaceEx(rootPathName, freeBytesToCaller, totalNumberOfBytes, totalNumberOfFreeBytes)
>>
>>        System.Console.WriteLine( "Free Bytes: " &  freeBytesToCaller.ToString() )
>>        System.Console.WriteLine( "Total Bytes: " &  totalNumberOfBytes.ToString() )
>>        System.Console.WriteLine( "Total Free Bytes: " &  totalNumberOfFreeBytes.ToString() )
>>
>>
>>end sub
>>end module
>>
>>
>>PS: \\poseidon\c$ exists on my my domain.
>
>This is the class I built last night but on UNC path, it doesn't even get into the For Each loop.
>
>
>Imports System.Management
>
>Namespace Framework
>
>    Public Class DriveInformation
>
>        Public cError As String = ""
>        Public cProviderName As String = ""
>        Public cVolumeName As String = ""
>        Public nFreeSpace As Double = 0
>
>        ' Type of drive
>        ' 1 Local drive
>        ' 2 UNC drive
>        Public nType As Integer = 1
>
>        Private oApp As Framework.App
>        Private oProcess As Framework.LXProcess
>
>        ' This is when we access the data provider in desktop and Web service mode
>        Sub New(ByVal toApplication As Framework.App)
>            oApp = toApplication
>        End Sub
>
>        ' This is when we access the data provider in a Web mode
>        Public Sub New(ByVal toProcess As Framework.LXProcess)
>            oProcess = toProcess
>            oApp = oProcess.oApp
>        End Sub
>
>        ' Get the information on a drive
>        Public Function GetFreeSpace() As Boolean
>            Dim lcSQL As String = ""
>            Dim llSuccess As Boolean = False
>            Dim loQuery As SelectQuery
>            Dim loManagementObject As ManagementObject
>            Dim loSearcher As ManagementObjectSearcher
>
>            ' Adjust SQL as per type of drive
>            Select Case nType
>
>                ' Local drive
>                Case 1
>                    lcSQL = "SELECT FreeSpace, QuotasDisabled ,VolumeName " + _
>                    "FROM Win32_LogicalDisk WHERE DeviceID = """ + cProviderName + """"
>
>                    ' UNC drive
>                Case 2
>                    lcSQL = "SELECT FreeSpace, QuotasDisabled ,VolumeName " + _
>                     "FROM Win32_LogicalDisk WHERE ProviderName = """ + cProviderName + """"
>
>            End Select
>
>            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")
>                    nFreeSpace = loManagementObject("Freespace")
>                    llSuccess = True
>                End If
>
>            Next
>            Return llSuccess
>        End Function
>
>    End Class
>
>End Namespace
>
>
>I will try your approach and will let you know. BTW, with the approach I tried to use, there was the ability to define a connection, for the username and password. Will there be a way to do that with your approach?

No. For that API assumes you've access. You can use other means to connect (ie: WNetAddConnection if using win32API).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform