'
专注于为中小企业提供网站设计制作、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业平湖免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了千余家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
'!!!重要:首先要添加“引用”一个dll,选择“System Management”;
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Management
Imports System.IO
Namespace WindowsApplication1
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取CPU编号
Dim [MyClass] As New ManagementClass("Win32_Processor")
Dim MyCollection As ManagementObjectCollection = [MyClass].GetInstances()
Dim MyInfo As String = "当前系统CPU编号是:"
Dim MyCPUID As String = ""
For Each MyObject As ManagementObject In MyCollection
MyCPUID = MyObject.Properties("ProcessorId").Value.ToString()
Exit For
Next MyObject
MyInfo = MyCPUID
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的当前电压
Dim MyInfo As String = "计算机CPU的当前电压是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
Try
MyInfo = ControlChars.Lf String.Format("CurrentVoltage : " MyObject("CurrentVoltage").ToString())
MyInfo = ControlChars.Lf "========================================================="
Catch
End Try
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的外部频率
Dim MyInfo As String = "计算机CPU的外部频率是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
Try
MyInfo = ControlChars.Lf String.Format("ExtClock : " MyObject("ExtClock").ToString())
MyInfo = ControlChars.Lf "========================================================="
Catch
End Try
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button4_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的二级缓存
Dim MyInfo As String = "计算机CPU的二级缓存尺寸是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("L2CacheSize: " MyObject("L2CacheSize").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button5_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的制造商名称
Dim MyInfo As String = "计算机CPU的制造商名称是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("Manufacturer : " MyObject("Manufacturer").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button6_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的产品名称
Dim MyInfo As String = "计算机CPU的产品名称是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("Name : " MyObject("Name").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button7_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的版本信息
Dim MyInfo As String = "计算机CPU的版本信息如下:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("Version: " MyObject("Version").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button8_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的当前使用百分比 注意要把SQLserver或者其他耗CPU的软件开着否则看不到效果就一直为0
Dim MyInfo As String = "计算机CPU的当前使用百分比是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("LoadPercentage : " MyObject("LoadPercentage").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button9_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的最大时钟频率
Dim MyInfo As String = "计算机CPU的最大时钟频率是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("MaxClockSpeed : " MyObject("MaxClockSpeed").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button10_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机CPU的当前时钟频率
Dim MyInfo As String = "计算机CPU的当前时钟频率是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("CurrentClockSpeed : " MyObject("CurrentClockSpeed").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button11_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机的CPU地址宽度
Dim MyInfo As String = "当前计算机的CPU地址宽度是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("AddressWidth: " MyObject("AddressWidth").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub button14_Click(ByVal sender As Object, ByVal e As EventArgs)
'获取计算机的CPU数据宽度
Dim MyInfo As String = "当前计算机的CPU数据宽度是:"
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
For Each MyObject As ManagementObject In MySearcher.Get()
MyInfo = ControlChars.Lf String.Format("DataWidth : " MyObject("DataWidth").ToString())
MyInfo = ControlChars.Lf "========================================================="
Next MyObject
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
每个 Visual Basic 应用程序均必须包含一个称为VB.NET Main过程。该过程为应用程序的起始点并为应用程序提供总体控制。.NET Framework 在已加载应用程序并准备将控制传递给它时,将调用 Main 过程。除非您要创建 Windows 窗体应用程序,否则就必须为自运行的应用程序编写 Main 过程。
Main 中包含首先运行的代码。在 Main 中,可以确定在程序启动时首先加载的窗体,确定系统上是否已在运行您的应用程序副本,为应用程序建立一组变量,或者打开应用程序需要的数据库。
VB.NET Main过程的要求
独立运行的文件(扩展名通常为 .exe)必须包含 Main 过程。库(例如,扩展名为 .dll)不独立运行,因而不需要 Main 过程。可以创建的不同类型的项目的要求如下:
控制台应用程序可以独立运行,而且您必须提供至少一个 Main 过程。
Windows 窗体应用程序可以独立运行。但是,Visual Basic 编译器会在此类应用程序中自动生成一个 Main 过程,因而您不需要编写此过程。
类库不需要 Main 过程。这些类库包括 Windows 控件库和 Web 控件库。作为类库部署 Web 应用程序。
声明VB.NET Main过程
有四种方法可以声明 Main 过程。它可以使用参数或不使用参数,可以返回值或不返回值。
注意
如果在类中声明 Main 过程,则必须使用 Shared 关键字。在模块中,Main 不必是 Shared。
最简单的方法是声明一个不使用参数或不返回值的 Sub 过程。
Module mainModule
Sub Main()
MsgBox("The Main procedure
is starting the application.")
' Insert call to appropriate
starting place in your code.
MsgBox("The application
is terminating.")
End Sub
End ModuleMain
还可以返回一个 Integer 值,操作系统将其作为程序的退出代码。其他程序可以通过检查 Windows ERRORLEVEL 值来测试该代码。若要返回退出代码,必须将VB.NET Main过程声明为 Function 过程而不是 Sub 过程。
Module mainModule
Function Main() As Integer
MsgBox("The Main procedure
is starting the application.")
Dim returnValue As Integer = 0
' Insert call to appropriate
starting place in your code.
' On return, assign appropriate
value to returnValue.
' 0 usually means successful
completion.
MsgBox("The application is
terminating with error level " _
CStr(returnValue) ".")
Return returnValue
End Function
End ModuleMain
还可以采用一个 String 数组作为参数。数组中的每个字符串均包含一个用于调用程序的命令行参数。您可以根据它们的值采取不同的操作。
Module mainModule
Function Main(ByVal cmdArgs()
As String) As Integer
MsgBox("The Main procedure is
starting the application.")
Dim returnValue As Integer = 0
' See if there are any arguments.
If cmdArgs.Length 0 Then
For argNum As Integer = 0 To
UBound(cmdArgs, 1)
' Insert code to examine cmdArgs
(argNum) and take
' appropriate action based on its value.
Next argNum
End If
' Insert call to appropriate starting
place in your code.
' On return, assign appropriate
value to returnValue.
' 0 usually means successful completion.
MsgBox("The application is
terminating with error level " _
CStr(returnValue) ".")
Return returnValue
End Function
End Module
可以声明VB.NET Main过程来检查命令行参数而不返回退出代码,如下所示。
Module mainModule
Sub Main(ByVal cmdArgs() As String)
MsgBox("The Main procedure is
starting the application.")
Dim returnValue As Integer = 0
' See if there are any arguments.
If cmdArgs.Length 0 Then
For argNum As Integer = 0 To
UBound(cmdArgs, 1)
' Insert code to examine cmdArgs
(argNum) and take
' appropriate action based on its value.
Next argNum
End If
' Insert call to appropriate
starting place in your code.
MsgBox("The application is
terminating."
End Sub
End Module
用一个数字做为流程标识这是可以的 但是如果用中文标识确实麻烦
给个方法参考
1:以两位数字表示流程 AB A表示序号,B表示结果 eg:11 这一阶段测试OK 20 第二阶段检测失败.或者更多也行[有点像上位机编程里的二进制数据用法,第几位到第几位是干什么用的,代表什么]
方法2 :因为流程固定,所以可以采用在数据库里给各流程步骤设计一个逻辑型的变量用于标识是否合格即可,
方法3: 也可以用不同的数据表来表示不同流程,用一个唯一id 进行关联即可
对于显示颜色 ,可以采用过程或者函数的方法节省代码