Imports System.Management Imports System.Runtime.InteropServices Namespace Framework Public Class DriveInformation Public cError As String = "" Public cProviderName As String = "" Public cVolumeName As String = "" Public nAvailableByte As Double = 0 Public nFreeSpace As Double = 0 Public nFreeSpaceToCaller 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 Public Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _ (ByVal lpRootPathName As String, _ ByRef lpFreeBytesAvailableToCaller As Double, _ ByRef lpTotalNumberOfBytes As Double, _ ByRef lpTotalNumberOfFreeBytes As Double) As Integer ' 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 ' Get the information on a drive Public Function GetFreeSpaceInteropServices() As Boolean GetDiskFreeSpaceEx(cProviderName, nFreeSpaceToCaller, nAvailableByte, nFreeSpace) Return True End Function End Class End NamespaceAnd, call it like that:
Dim loDriveInformation As Framework.Framework.DriveInformation = New Framework.Framework.DriveInformation(oProcess) loDriveInformation.cProviderName = "\\1.1.1.1\D$" If loDriveInformation.GetFreeSpaceInteropServices() Then Throw New System.Exception(loDriveInformation.cVolumeName + " " + loDriveInformation.nFreeSpace.ToString + _ loDriveInformation.nAvailableByte.ToString + " " + loDriveInformation.nFreeSpaceToCaller.ToString) Else Throw New System.Exception("not working") End IfYou will have to adjust the calling code to represent your UNC remote path as well as the declaration. Then, you may let me know if from that code as is if you are able to get the drive information from a UNC remote path from VB.NET.