| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> WMI编程 >> 实例分析正文
最新推荐 更多内容
[图文]VB.Net查询光驱信息的实例[乐博网原创]
VB.Net查询光驱信息的实例[乐博网原创]
作者:Shiny    来源:乐博网原创     更新时间:2007-12-18

此文章为本站(Lob.cn)乐博网原创,可以自由转载和传播,但希望能保留本站的作者和信息来源,谢谢!如果大家对此问题或者关于VB.Net调用WMI实现系统管理的话题感兴趣,就一起加入讨论把他做得更完善吧!

VB.Net调用WMI可以实现系统管理和系统信息查询等。WMI全称为Windows Management Instrumentation,利用WMI我们可以实现很多系统管理的功能,msdn在.Net Framework类库中对此描述比较简单(因为早期WMI相关专题有所较详尽描述,故类库中未再详细解说与演示) 乐博网将发布一系列相关文章及实例分析帮助大家更深刻了解它。

开发环境: VB2005  Windows2003

本实例需要在菜单栏中的“项目”-“ 添加引用” -“ System.Management”

并在实例代码中导入引用的项目和程序集中定义的命名空间或编程元素 即: Imports System.Management  

VB.Net查询光驱信息的实例

  

代码如下:

   Private Sub Lobdotcn()

        Dim Lob_Searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_CDROMDrive")
        For Each Obj_Query As ManagementObject In Lob_Searcher.Get()
            ListBox1.Items.Add("乐博网LOB.Cn   VB.Net爱好者的组织")
            ListBox1.Items.Add("Availability: " & Obj_Query("Availability"))
            ListBox1.Items.Add("Caption: " & Obj_Query("Caption"))
            If Obj_Query("Capabilities") IsNot Nothing Then
                Dim arrCapabilities As UInt16()
                arrCapabilities = Obj_Query("Capabilities")
                For Each arrValue As UInt16 In arrCapabilities
                    ListBox1.Items.Add("Availability(): " & arrValue)
                Next
            End If
            If Obj_Query("CapabilityDescriptions") IsNot Nothing Then
                Dim arrCapabilityDescriptions As String()
                arrCapabilityDescriptions = Obj_Query("CapabilityDescriptions")
                For Each arrValue As String In arrCapabilityDescriptions
                    ListBox1.Items.Add("CapabilityDescriptions(): " & arrValue)
                Next
            End If
            ListBox1.Items.Add("CompressionMethod: " & Obj_Query("CompressionMethod"))
            ListBox1.Items.Add("ConfigManagerErrorCode: " & Obj_Query("ConfigManagerErrorCode"))
            ListBox1.Items.Add("ConfigManagerUserConfig: " & Obj_Query("ConfigManagerUserConfig"))
            ListBox1.Items.Add("CreationClassName: " & Obj_Query("CreationClassName"))
            ListBox1.Items.Add("DefaultBlockSize: " & Obj_Query("DefaultBlockSize"))
            ListBox1.Items.Add("Description: " & Obj_Query("Description"))
            ListBox1.Items.Add("DeviceID: " & Obj_Query("DeviceID"))
            ListBox1.Items.Add("Drive: " & Obj_Query("Drive"))
            ListBox1.Items.Add("DriveIntegrity: " & Obj_Query("DriveIntegrity"))
            ListBox1.Items.Add("ErrorCleared: " & Obj_Query("ErrorCleared"))
            ListBox1.Items.Add("ErrorDescription: " & Obj_Query("ErrorDescription"))
            ListBox1.Items.Add("ErrorMethodology: " & Obj_Query("ErrorMethodology"))
            ListBox1.Items.Add("FileSystemFlags: " & Obj_Query("FileSystemFlags"))
            ListBox1.Items.Add("FileSystemFlagsEx: " & Obj_Query("FileSystemFlagsEx"))
            ListBox1.Items.Add("InstallDate: " & Obj_Query("InstallDate"))
            ListBox1.Items.Add("LastErrorCode: " & Obj_Query("LastErrorCode"))
            ListBox1.Items.Add("Manufacturer: " & Obj_Query("Manufacturer"))
            ListBox1.Items.Add("MaxBlockSize: " & Obj_Query("MaxBlockSize"))
            ListBox1.Items.Add("MaximumComponentLength: " & Obj_Query("MaximumComponentLength"))
            ListBox1.Items.Add("MaxMediaSize: " & Obj_Query("MaxMediaSize"))
            ListBox1.Items.Add("MediaLoaded: " & Obj_Query("MediaLoaded"))
            ListBox1.Items.Add("MediaType: " & Obj_Query("MediaType"))
            ListBox1.Items.Add("MfrAssignedRevisionLevel: " & Obj_Query("MfrAssignedRevisionLevel"))
            ListBox1.Items.Add("MinBlockSize: " & Obj_Query("MinBlockSize"))
            ListBox1.Items.Add("Name: " & Obj_Query("Name"))
            ListBox1.Items.Add("NeedsCleaning: " & Obj_Query("NeedsCleaning"))
            ListBox1.Items.Add("NumberOfMediaSupported: " & Obj_Query("NumberOfMediaSupported"))
            ListBox1.Items.Add("PNPDeviceID: " & Obj_Query("PNPDeviceID"))
            If Obj_Query("PowerManagementCapabilities") IsNot Nothing Then
                Dim arrPowerManagementCapabilities As UInt16()
                arrPowerManagementCapabilities = Obj_Query("PowerManagementCapabilities")
                For Each arrValue As UInt16 In arrPowerManagementCapabilities
                    ListBox1.Items.Add("PowerManagementCapabilities(): " & arrValue)
                Next
            End If
            ListBox1.Items.Add("PowerManagementSupported: " & Obj_Query("PowerManagementSupported"))
            ListBox1.Items.Add("RevisionLevel: " & Obj_Query("RevisionLevel"))
            ListBox1.Items.Add("SCSIBus: " & Obj_Query("SCSIBus"))
            ListBox1.Items.Add("SCSILogicalUnit: " & Obj_Query("SCSILogicalUnit"))
            ListBox1.Items.Add("SCSIPort: " & Obj_Query("SCSIPort"))
            ListBox1.Items.Add("SCSITargetId: " & Obj_Query("SCSITargetId"))
            ListBox1.Items.Add("Size: " & Obj_Query("Size"))
            ListBox1.Items.Add("Status: " & Obj_Query("Status"))
            ListBox1.Items.Add("StatusInfo: " & Obj_Query("StatusInfo"))
            ListBox1.Items.Add("SystemCreationClassName: " & Obj_Query("SystemCreationClassName"))
            ListBox1.Items.Add("SystemName: " & Obj_Query("SystemName"))
            ListBox1.Items.Add("TransferRate: " & Obj_Query("TransferRate"))
            ListBox1.Items.Add("VolumeName: " & Obj_Query("VolumeName"))
            ListBox1.Items.Add("VolumeSerialNumber: " & Obj_Query("VolumeSerialNumber"))
        Next

    End Sub

相关属性说明:

uint16 Availability;
  uint16 Capabilities[];
  string CapabilityDescriptions[];
  string Caption;
  string CompressionMethod;
  uint32 ConfigManagerErrorCode;
  boolean ConfigManagerUserConfig;
  string CreationClassName;
  uint64 DefaultBlockSize;
  string Description;
  string DeviceID;
  string Drive;
  boolean DriveIntegrity;
  boolean ErrorCleared;
  string ErrorDescription;
  string ErrorMethodology;
  uint16 FileSystemFlags;
  uint32 FileSystemFlagsEx;
  string Id;
  datetime InstallDate;
  uint32 LastErrorCode;
  string Manufacturer;
  uint64 MaxBlockSize;
  uint32 MaximumComponentLength;
  uint64 MaxMediaSize;
  boolean MediaLoaded;
  string MediaType;
  string MfrAssignedRevisionLevel;
  uint64 MinBlockSize;
  string Name;
  boolean NeedsCleaning;
  uint32 NumberOfMediaSupported;
  string PNPDeviceID;
  uint16 PowerManagementCapabilities[];
  boolean PowerManagementSupported;
  string RevisionLevel;
  uint32 SCSIBus;
  uint16 SCSILogicalUnit;
  uint16 SCSIPort;
  uint16 SCSITargetId;
  uint16 SerialNumber;
  uint64 Size;
  string Status;
  uint16 StatusInfo;
  string SystemCreationClassName;
  string SystemName;
  real64 TransferRate;
  string VolumeName;
  string VolumeSerialNumber;

Availability
Data type: uint16
Access type: Read-only

Availability and status of the device. Inherited from CIM_LogicalDevice.

Value Meaning

1
0x1

Other

2
0x2

Unknown

3
0x3

Running or Full Power

4
0x4

Warning

5
0x5

In Test

6
0x6

Not Applicable

7
0x7

Power Off

8
0x8

Off Line

9
0x9

Off Duty

10
0xA

Degraded

11
0xB

Not Installed

12
0xC

Install Error

13
0xD

Power Save - Unknown

The device is known to be in a power save mode, but its exact status is unknown.

14
0xE

Power Save - Low Power Mode

The device is in a power save state but still functioning, and may exhibit degraded performance.

15
0xF

Power Save - Standby

The device is not functioning, but could be brought to full power quickly.

16
0x10

Power Cycle

17
0x11

Power Save - Warning

The device is in a warning state, though also in a power save mode.

Capabilities
Data type: uint16 array
Access type: Read-only

Array of capabilities of the media access device. For example, the device may support random access (3), removable media (7), and automatic cleaning (9). This property is inherited from CIM_MediaAccessDevice.

Value Meaning

0

Unknown

1

Other

2

Sequential Access

3

Random Access

4

Supports Writing

5

Encryption

6

Compression

7

Supports Removable Media

8

Manual Cleaning

9

Automatic Cleaning

10

SMART Notification

11

Supports Dual-Sided Media

12

Predismount Eject Not Required

CapabilityDescriptions
Data type: string array
Access type: Read-only

Array of more detailed explanations for any of the access device features indicated in the Capabilities array. Each entry of this array is related to the entry in the Capabilities array that is located at the same index. This property is inherited from CIM_MediaAccessDevice.

Caption
Data type: string
Access type: Read-only

Short description of the object—a one-line string. This property is inherited from CIM_ManagedSystemElement.

CompressionMethod
Data type: string
Access type: Read-only

Algorithm or tool used by the device to support compression. If it is not possible or not desired to describe the compression scheme (perhaps because it is not known), use the following words: "Unknown" to represent that it is not known whether the device supports compression capabilities; "Compressed" to represent that the device supports compression capabilities but either its compression scheme is not known or not disclosed; and "Not Compressed" to represent that the device does not support compression capabilities. This property is inherited from CIM_MediaAccessDevice.

ConfigManagerErrorCode
Data type: uint32
Access type: Read-only

Windows Configuration Manager error code.

Value Meaning

0
0x0

Device is working properly.

1
0x1

Device is not configured correctly.

2
0x2

Windows cannot load the driver for this device.

3
0x3

Driver for this device might be corrupted, or the system may be low on memory or other resources.

4
0x4

Device is not working properly. One of its drivers or the registry might be corrupted.

5
0x5

Driver for the device requires a resource that Windows cannot manage.

6
0x6

Boot configuration for the device conflicts with other devices.

7
0x7

Cannot filter.

8
0x8

Driver loader for the device is missing.

9
0x9

Device is not working properly. The controlling firmware is incorrectly reporting the resources for the device.

10
0xA

Device cannot start.

11
0xB

Device failed.

12
0xC

Device cannot find enough free resources to use.

13
0xD

Windows cannot verify the device's resources.

14
0xE

Device cannot work properly until the computer is restarted.

15
0xF

Device is not working properly due to a possible re-enumeration problem.

16
0x10

Windows cannot identify all of the resources that the device uses.

17
0x11

Device is requesting an unknown resource type.

18
0x12

Device drivers must be reinstalled.

19
0x13

Failure using the VxD loader.

20
0x14

Registry might be corrupted.

21
0x15

System failure. If changing the device driver is ineffective, see the hardware documentation. Windows is removing the device.

22
0x16

Device is disabled.

23
0x17

System failure. If changing the device driver is ineffective, see the hardware documentation.

24
0x18

Device is not present, not working properly, or does not have all of its drivers installed.

25
0x19

Windows is still setting up the device.

26
0x1A

Windows is still setting up the device.

27
0x1B

Device does not have valid log configuration.

28
0x1C

Device drivers are not installed.

29
0x1D

Device is disabled. The device firmware did not provide the required resources.

30
0x1E

Device is using an IRQ resource that another device is using.

31
0x1F

Device is not working properly. Windows cannot load the required device drivers.

ConfigManagerUserConfig
Data type: boolean
Access type: Read-only

If True, the device is using a user-defined configuration. This property is inherited from CIM_LogicalDevice.

[1] [2] 下一页

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    VB.Net控制光驱开关的实例
    计算机加入域或工作组的实例
    VB.Net查询显示器属性信息的实例[乐博网原创]
    VB.Net查询系统启动信息的实例[乐博网原创]
    VB.Net查询键盘类型的实例[乐博网原创]
    VB.Net查询BIOS版本信息的实例[乐博网原创]
    VB.Net查询哪些服务可以被手工停止的方法
    VB.Net不用ping.exe实现ping主机是否通的方法
    VB.Net查询开机自启动项目的方法
    VB.Net查询屏幕分辨率的方法
    VB.Net查询系统日志明细的方法
    VB.Net清理系统日志的方法
    VB.Net查询日志记录条数和日志大小上限的方法
    VB.Net实现磁盘碎片整理的方法
    VB.Net检测所有磁盘文件系统类型的方法
    VB.Net检测所有磁盘类型的方法

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]