Free Disk Space on Remote Computer

Public Sub GetFreeDiskSpace(ByVal strComputer As String, ByVal strUserName As String, ByVal strPwd As String)

        Dim query As Management.ManagementObjectSearcher
        Dim queryCollection As Management.ManagementObjectCollection
        Dim management_object1 As Management.ManagementObject
        Dim msc As Management.ManagementScope

        If (strComputer = System.Environment.MachineName) Then
            msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2")
        Else
            Dim co As New Management.ConnectionOptions
            co.Username = strUserName
            co.Password = strPwd
            msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
        End If

        Dim query_command As String = "SELECT * FROM Win32_LogicalDisk"
        Dim select_query As Management.SelectQuery = New Management.SelectQuery(query_command)

        Try
            query = New Management.ManagementObjectSearcher(msc, select_query)
            queryCollection = query.Get()
            Dim strDisk As String = ""
            For Each management_object1 In queryCollection

                strDisk = "Drive Letter: " & management_object1("DeviceID") & vbCrLf & "File System: " & management_object1("FileSystem") & vbCrLf & "Total Space: " & ((CType(management_object1("Size"), String) / 1024) / 1024) / 1024 & " GB" & vbCrLf & "Free Space: " & ((CType(management_object1("FreeSpace"), String) / 1024) / 1024) / 1024 & " GB"

                MessageBox.Show(strDisk)
            Next management_object1
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try

End Sub

Related Posts by Categories



Stumble This Fav This With Technorati Add To Del.icio.us Digg This Add To Reddit Add To Facebook Add To Yahoo

0 comments:

Post a Comment