Imports System
Imports System.Management
Module Module1
Sub Main()
CalculateFreeUsed("\\MyServer\ShareA")
End Sub
Sub CalculateFreeUsed(ByVal srvname As String)
Try
Dim oConn As ConnectionOptions = New ConnectionOptions
Dim strNameSpace As String
If srvname <> "" Then
strNameSpace += srvname
Else
strNameSpace += "."
strNameSpace += "\root\cimv2"
End If
Dim oMs As New ManagementScope(strNameSpace, oConn)
Dim oQuery As New ObjectQuery("select FreeSpace,Size,Name from
Win32_LogicalDisk where DriveType=3")
'Execute the query
'Get the results
Dim oReturnCollection As ManagementObjectCollection
Dim search As New ManagementObjectSearcher(oMs, oQuery)
' Display each entry for Win32_processor
Dim info As ManagementObject
For Each info In search.Get()
Dim strFreespace As String = info("FreeSpace").ToString()
Dim D_Freespace As Integer = D_Freespace + System.Convert.ToDouble
(strFreespace)
Console.WriteLine(D_Freespace & vbCrLf)
'Size in bytes
Dim strTotalspace As String = info("Size").ToString()
Dim D_Totalspace As Integer = D_Totalspace + System.Convert.ToDouble
(strTotalspace)
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Module
[\code]