Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot used DriveInfo() on UNC drive
Message
From
01/11/2006 07:33:50
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/11/2006 01:26:55
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:
01166091
Views:
14
>I am trying to use the DriveInfo() class to get some information from a UNC drive. However, this doesn't seem to be possible. I keep getting:
>
>Object must be a root directory ("C:\") or a drive letter ("C").
>
>How can someone use DriveInfo() on a UNC drive?

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