>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