| 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> WMI编程 >> 实例分析正文
最新推荐 更多内容
[图文]磁盘卷标编程(VB2005实例)
磁盘卷标编程(VB2005实例)
作者:Shiny    来源:乐博网原创     更新时间:2011-4-6

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

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

开发环境: VB2005  Windows2003

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

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

效果图:

 

源代码如下:

Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

    Public Class MyWMIQuery

        Public Overloads Shared Function Main() As Integer

            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_Volume")

                For Each queryObj As ManagementObject in searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Win32_Volume instance乐博网lob.cn提供")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Access: {0}", queryObj("Access"))
                    Console.WriteLine("Automount: {0}", queryObj("Automount"))
                    Console.WriteLine("Availability: {0}", queryObj("Availability"))
                    Console.WriteLine("BlockSize: {0}", queryObj("BlockSize"))
                    Console.WriteLine("Capacity: {0}", queryObj("Capacity"))
                    Console.WriteLine("Caption: {0}", queryObj("Caption"))
                    Console.WriteLine("Compressed: {0}", queryObj("Compressed"))
                    Console.WriteLine("ConfigManagerErrorCode: {0}", queryObj("ConfigManagerErrorCode"))
                    Console.WriteLine("ConfigManagerUserConfig: {0}", queryObj("ConfigManagerUserConfig"))
                    Console.WriteLine("CreationClassName: {0}", queryObj("CreationClassName"))
                    Console.WriteLine("Description: {0}", queryObj("Description"))
                    Console.WriteLine("DeviceID: {0}", queryObj("DeviceID"))
                    Console.WriteLine("DirtyBitSet: {0}", queryObj("DirtyBitSet"))
                    Console.WriteLine("DriveLetter: {0}", queryObj("DriveLetter"))
                    Console.WriteLine("DriveType: {0}", queryObj("DriveType"))
                    Console.WriteLine("ErrorCleared: {0}", queryObj("ErrorCleared"))
                    Console.WriteLine("ErrorDescription: {0}", queryObj("ErrorDescription"))
                    Console.WriteLine("ErrorMethodology: {0}", queryObj("ErrorMethodology"))
                    Console.WriteLine("FileSystem: {0}", queryObj("FileSystem"))
                    Console.WriteLine("FreeSpace: {0}", queryObj("FreeSpace"))
                    Console.WriteLine("IndexingEnabled: {0}", queryObj("IndexingEnabled"))
                    Console.WriteLine("InstallDate: {0}", queryObj("InstallDate"))
                    Console.WriteLine("Label: {0}", queryObj("Label"))
                    Console.WriteLine("LastErrorCode: {0}", queryObj("LastErrorCode"))
                    Console.WriteLine("MaximumFileNameLength: {0}", queryObj("MaximumFileNameLength"))
                    Console.WriteLine("Name: {0}", queryObj("Name"))
                    Console.WriteLine("NumberOfBlocks: {0}", queryObj("NumberOfBlocks"))
                    Console.WriteLine("PNPDeviceID: {0}", queryObj("PNPDeviceID"))

                    If queryObj("PowerManagementCapabilities") Is Nothing Then
                        Console.WriteLine("PowerManagementCapabilities: {0}", queryObj("PowerManagementCapabilities"))
                    Else
                        Dim arrPowerManagementCapabilities As UInt16()
                        arrPowerManagementCapabilities = queryObj("PowerManagementCapabilities")
                        For Each arrValue As UInt16 In arrPowerManagementCapabilities
                            Console.WriteLine("PowerManagementCapabilities: {0}", arrValue)
                        Next
                    End If
                    Console.WriteLine("PowerManagementSupported: {0}", queryObj("PowerManagementSupported"))
                    Console.WriteLine("Purpose: {0}", queryObj("Purpose"))
                    Console.WriteLine("QuotasEnabled: {0}", queryObj("QuotasEnabled"))
                    Console.WriteLine("QuotasIncomplete: {0}", queryObj("QuotasIncomplete"))
                    Console.WriteLine("QuotasRebuilding: {0}", queryObj("QuotasRebuilding"))
                    Console.WriteLine("SerialNumber: {0}", queryObj("SerialNumber"))
                    Console.WriteLine("Status: {0}", queryObj("Status"))
                    Console.WriteLine("StatusInfo: {0}", queryObj("StatusInfo"))
                    Console.WriteLine("SupportsDiskQuotas: {0}", queryObj("SupportsDiskQuotas"))
                    Console.WriteLine("SupportsFileBasedCompression: {0}", queryObj("SupportsFileBasedCompression"))
                    Console.WriteLine("SystemCreationClassName: {0}", queryObj("SystemCreationClassName"))
                    Console.WriteLine("SystemName: {0}", queryObj("SystemName"))
                Next
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Function
    End Class
End Namespace

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    WMI编程实例(VB2010实例)
    创建系统服务(VB2005实例)
    共享文件夹管理(VB2005实例)
    系统服务管理(VB2005实例)
    计算机加入域或工作组的实例
    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开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]
    百度