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

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 实例学习笔记 >> 实例分析正文
最新推荐 更多内容
WMI编程实例(VB2010实例)
WMI编程实例(VB2010实例)
作者:Akyao    来源:乐博网收集     更新时间:2011-4-18

本文演示如何使用 System.Management 命令空间中的对象访问 Windows Management Instrumentation (WMI) 和查询系统信息,如操作系统名称、版本、制造商和计算机名称,来自乐博网。

如果你想下载本文的源代码RAR压缩集合包  请访问
VB2010源代码集合包(芋头糕)    http://www.lob.cn/code/utility/2795.shtml
特别感谢网友 芋头糕 将此资源提供乐博网分享,欢迎加入 40797788 的.Net超级qq群交流。

WMI编程实例代码如下:

' Copyright (c) Microsoft Corporation. All rights reserved.
Imports System.Management

Public Class MainForm


    ' This subroutine fills in the output text box with bios information from WMI
    Private Sub btnBios_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBios.Click
        ' This is to show how to use the SelectQuery object in the place of a SELECT
        ' statement.
        Dim query As New SelectQuery("Win32_bios")

        'ManagementObjectSearcher retrieves a collection of WMI objects based on
        ' the query.
        Dim search As New ManagementObjectSearcher(query)

        ' Display each entry for Win32_bios
        Dim info As ManagementObject
        For Each info In search.Get()
            txtOutput.Text = "Bios version: " & info("version").ToString() & vbCrLf
        Next
    End Sub

    ' This subroutine fills in the output text box with computer system information
    ' from WMI
    Private Sub btnComputerSystem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComputerSystem.Click
        ' ManagementObjectSearcher retrieves a collection of WMI objects based on
        ' the query.  In this case a string is used instead of a SelectQuery object.
        Dim search As New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")

        ' Display each entry for Win32_ComputerSystem
        Dim info As ManagementObject
        For Each info In search.Get()
            txtOutput.Text = "Manufacturer: " & info("manufacturer").ToString() & vbCrLf
            txtOutput.Text &= "Model: " & info("model").ToString() & vbCrLf
            txtOutput.Text &= "System Type: " & info("systemtype").ToString() & vbCrLf
            txtOutput.Text &= "Total Physical Memory: " & _
                info("totalphysicalmemory").ToString() & vbCrLf
        Next
    End Sub

    ' This subroutine fills a list box with all WMI classes.
    Private Sub btnClassEnum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClassEnum.Click
        ' Clear out the list box
        lstWMIClasses.Items.Clear()

        ' Default constructor for ManagementClass will return cim root. 
        Dim root As New ManagementClass()

        ' If Subclasses checkbox check we will get all subclasses as well as the top
        ' level classes.
        Dim options As New EnumerationOptions()
        options.EnumerateDeep = chkIncludeSubclasses.Checked

        ' Add each WMI class in the enumeration to the list box.
        Dim info As ManagementObject '更多.net源代码 来自乐博网 lob.cn
        For Each info In root.GetSubclasses(options)
            lstWMIClasses.Items.Add(info("__Class"))
        Next
    End Sub

    ' This subroutine fills in the output text box with Operating System information
    ' from WMI
    Private Sub btnOperatingSytem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOperatingSytem.Click
        ' ManagementObjectSearcher retrieves a collection of WMI objects based on
        ' the query.  In this case a string is used instead of a SelectQuery object.
        Dim search As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

        ' Display each entry for Win32_OperatingSystem
        Dim info As ManagementObject
        For Each info In search.Get()
            txtOutput.Text = "Name: " & info("name").ToString() & vbCrLf
            txtOutput.Text &= "Version: " & info("version").ToString() & vbCrLf
            txtOutput.Text &= "Manufacturer: " & info("manufacturer").ToString() & vbCrLf
            txtOutput.Text &= "Computer name: " & info("csname").ToString() & vbCrLf
            txtOutput.Text &= "Windows Directory: " & _
                info("windowsdirectory").ToString() & vbCrLf
        Next
    End Sub

    ' This subroutine fills in the output text box with Processor information
    ' from WMI
    Private Sub btnProcessor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcessor.Click
        ' This is to show how to use the SelectQuery object in the place of a SELECT
        ' statement.
        Dim query As New SelectQuery("Win32_processor")

        'ManagementObjectSearcher retrieves a collection of WMI objects based on
        ' the query.
        Dim search As New ManagementObjectSearcher(query)

        ' Display each entry for Win32_processor
        Dim info As ManagementObject
        For Each info In search.Get()
            txtOutput.Text = "Processor: " & info("caption").ToString() & vbCrLf
        Next
    End Sub

    ' This subroutine fills in the output text box with Time zone information from WMI
    Private Sub btnTimeZone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimeZone.Click
        ' This is to show how to use the SelectQuery object in the place of a SELECT
        ' statement.
        Dim query As New SelectQuery("Win32_timezone")

        'ManagementObjectSearcher retrieves a collection of WMI objects based on
        ' the query.
        Dim search As New ManagementObjectSearcher(query)

        ' Display each entry for Win32_timezone
        Dim info As ManagementObject
        For Each info In search.Get()
            txtOutput.Text = "乐博网Time zone: " & info("caption").ToString() & vbCrLf
        Next
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
End Class

  • 上一篇:

  • 下一篇: 没有了
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    管理计算机电源状态的类(VB2010实例)
    Tablet PC 上可用的文本识别选项(VB2010实例)
    Tablet PC 2005 中对笔势的系统识别(VB2010实例)
    自定义数据控件(VB2010实例)
    Tablet PC 2005 的区分上下文功能(VB2010实例)
    响应数字化仪触笔背面的橡皮擦(VB2010实例)
    系统服务管理实例(VB2010实例)
    创建系统服务(VB2005实例)
    磁盘卷标编程(VB2005实例)
    共享文件夹管理(VB2005实例)
    系统服务管理(VB2005实例)
    进程管理(VB2010实例)
    显示进程组成模块(VB2010实例)
    任务管理器编程(VB2010实例)
    性能计数器编程(VB2010实例)
    消息队列MSMQListener(VB2010实例)

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