VB.Net调用WMI可以实现系统管理和系统信息查询等。msdn上只有C++和vbs脚本演示,乐博网在vbs脚本基础上将发布WMI系列文章演示如何将WMI应用到VB.Net上。
调试环境 vb2005 windows2003
VB.Net检测所有磁盘类型的方法 磁盘类型分本地磁盘 可移动磁盘 网络磁盘 RAM映射的磁盘等
Private Sub Lobdotcn()
Dim strComputer As String = "." Dim objWMIService As Object = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Dim colDisks As Object = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk") Dim objDisk As Object For Each objDisk In colDisks MsgBox("DeviceID: " & vbTab _ & objDisk.DeviceID) Select Case objDisk.DriveType Case 1 MsgBox("No root directory. " _ & "Drive type could not be " _ & "determined.") Case 2 MsgBox("DriveType: " & vbTab _ & "Removable drive.") Case 3 MsgBox("DriveType: " & vbTab _ & "Local hard disk.") Case 4 MsgBox("DriveType: " & vbTab _ & "Network disk.") Case 5 MsgBox("DriveType: " & vbTab _ & "Compact disk.") Case 6 MsgBox("DriveType: " & vbTab _ & "RAM disk.") Case Else MsgBox("Drive type could not be" _ & " determined.") End Select Next
End Sub
|