七、得到CD-ROM信息
Imports System.Management Public Class Form1 Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New() MyBase.New()
'该调用是 Windows 窗体设计器所必需的。 InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub
'Windows 窗体设计器所必需的 '注意: 以下过程是 Windows 窗体设计器所必需的 '可以使用 Windows 窗体设计器修改此过程。 '不要使用代码编辑器修改它。 Private components As System.ComponentModel.IContainer Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Private Sub InitializeComponent() Me.ListBox1 = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'ListBox1 ' Me.ListBox1.Location = New System.Drawing.Point(24, 16) Me.ListBox1.Name = "ListBox1" Me.ListBox1.Size = New System.Drawing.Size(416, 173) Me.ListBox1.TabIndex = 0 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(456, 206) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load On Error Resume Next Dim SoundDeviceQuery As New SelectQuery("Win32_CDROMDrive") Dim SoundDeviceSearch As New ManagementObjectSearcher(SoundDeviceQuery) Dim SoundDeviceInfo As ManagementObject For Each SoundDeviceInfo In SoundDeviceSearch.Get() Dim SizeInMBs As Long = (Val(SoundDeviceInfo("Size").ToString())) SizeInMBs = Int((SizeInMBs / (1024 * 1024))) ListBox1.Items.Add("CD-Rom Description: " & SoundDeviceInfo("caption").ToString()) ListBox1.Items.Add("CD-Rom Manufacturer: " & SoundDeviceInfo("Manufacturer").ToString()) ListBox1.Items.Add("CD-Rom Drive: " & SoundDeviceInfo("drive").ToString()) ListBox1.Items.Add("CD-Rom Media Loaded: " & SoundDeviceInfo("MediaLoaded").ToString()) ListBox1.Items.Add("CD-Rom Media Type: " & SoundDeviceInfo("MediaType").ToString()) ListBox1.Items.Add("CD-Rom Volume Name: " & SoundDeviceInfo("VolumeName").ToString()) ListBox1.Items.Add("CD-Rom Size: " & SizeInMBs & " MBytes") ListBox1.Items.Add("CD-Rom Status: " & SoundDeviceInfo("Status").ToString()) ListBox1.Items.Add("CD-Rom MaxMediaSize: " & SoundDeviceInfo("MaxMediaSize").ToString()) ListBox1.Items.Add("CD-Rom Id: " & SoundDeviceInfo("Id").ToString()) ListBox1.Items.Add("CD-Rom TransferRate: "+Int(SoundDeviceInfo("TransferRate").ToString())+" KBs/秒") Next End Sub End Class
|