获取磁盘信息的实例
分类:VB.Net
测试平台:VS2005 + .Net Framework 3.5sp1 + Windows2003/xp
代码如下:
' 导入命名空间 Imports System.IO Imports System.Text Public Class LOB
Private Sub btnGetDriveInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDriveInfo.Click
' 显示一个状态讯息对话框来表示我们目前要尝试取得计算机的磁盘信息。 Dim frmStatusMessage As New frmStatus frmStatusMessage.Show("提示:处理中,请稍后....")
Dim sb As StringBuilder = New StringBuilder
' 宣告 DriveInfo 类别对象, 并使用 GetDrives 方法取得目前 ' 系统中所有逻辑磁盘驱动器的 DriveInfo 型别数组。 Dim myAllDrives As DriveInfo() = DriveInfo.GetDrives
Try For Each myDrive As DriveInfo In myAllDrives ' 使用 IsReady 属性判断磁盘装置是否就绪。 If myDrive.IsReady Then sb.Append("磁盘驱动器代号:") sb.AppendLine(myDrive.Name) sb.Append("磁盘卷标:") sb.AppendLine(myDrive.VolumeLabel) sb.Append("磁盘类型:") sb.AppendLine(myDrive.DriveType.ToString) sb.Append("磁盘格式:") sb.AppendLine(myDrive.DriveFormat) sb.Append("磁盘大小:") sb.AppendLine(myDrive.TotalSize.ToString) sb.Append("剩余空间:") sb.AppendLine(myDrive.AvailableFreeSpace.ToString) sb.Append("提示:总剩余空间(含磁盘配额)") sb.AppendLine(myDrive.TotalFreeSpace.ToString) sb.AppendLine("------------------------------------------------------------") End If Next Catch ex As Exception MessageBox.Show(ex.Message) End Try frmStatusMessage.Close() txtResult.Text = sb.ToString End Sub
Private Sub txtResult_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtResult.TextChanged
End Sub End Class
|
阅读(311) | 评论(0) | 转发(0) |