>>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 >>>>
>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 >>