VB 我不熟,下面是用汇编写的,我运行过可以的。
成都网站设计、网站制作,成都做网站公司-创新互联已向上1000家企业提供了,网站设计,网站制作,网络营销等服务!设计与技术结合,多年网站推广经验,合理的价格为您打造企业品质网站。
//--------------------------------
.model small
.586
.stack
.code
idstring db 49 dup('$')
start:
mov ax,@code
mov ds,ax
lea di,idstring
mov eax,80000002h
cpuid
mov dword ptr [di],eax
mov dword ptr [di+4],ebx
mov dword ptr [di+8],ecx
mov dword ptr [di+12],edx
mov eax,80000003h
cpuid
mov dword ptr [di+16],eax
mov dword ptr [di+20],ebx
mov dword ptr [di+24],ecx
mov dword ptr [di+28],edx
mov eax,80000004h
cpuid
mov dword ptr [di+32],eax
mov dword ptr [di+36],ebx
mov dword ptr [di+40],ecx
mov dword ptr [di+44],edx
mov ah,09h
lea dx,idstring
int 21h
mov ah,4ch
int 21h
end start
//-------------------------------------------------------
程序确实可以执行,输出CPU的ID等信息。
注意:DOS下或MS-DOS下使用。
使用wmi
类“Win32_Processor”中LoadPercentage属性为当前的cpu使用率
示例代码: Private Sub Timer1_Timer()
Dim WMI服务 As Object
Dim 对象 As Object
Dim 子对象 As Object
Dim 电脑名 As String
Dim 刷新 As Long
刷新 = 0
电脑名 = "." '表示本地计算机
Set WMI服务 = GetObject("winmgmts://" 电脑名 "/root/cimv2")
Set 对象 = WMI服务.InstancesOf("Win32_Processor")
Me.CurrentX = 0
Me.CurrentY = 0
For Each 子对象 In 对象
If 刷新 = 0 Then
刷新 = 1
Me.Cls
End If
Me.Print 子对象.Name "[" 子对象.CurrentClockSpeed "Hz] 使用率:" _
子对象.LoadPercentage "%"
Next
End Sub
CPU位数获取不了,核心数可以,能够用程序侦测出的,可以点我的电脑,右键属性
使用wmi
类“Win32_Processor”中LoadPercentage属性为当前的cpu使用率
示例代码: Private Sub Timer1_Timer()
Dim WMI服务 As Object
Dim 对象 As Object
Dim 子对象 As Object
Dim 电脑名 As String
Dim 刷新 As Long
刷新 = 0
电脑名 = "." '表示本地计算机
Set WMI服务 = GetObject("winmgmts://" 电脑名 "/root/cimv2")
Set 对象 = WMI服务.InstancesOf("Win32_Processor")
Me.CurrentX = 0
Me.CurrentY = 0
For Each 子对象 In 对象
If 刷新 = 0 Then
刷新 = 1
Me.Cls
End If
Me.Print 子对象.Name "[" 子对象.CurrentClockSpeed "Hz] 使用率:" _
子对象.LoadPercentage "%"
Next
End Sub
Imports System
Imports System.Management
Module Module1
Sub Main()
Dim scope As New ManagementScope("\\.\root\cimv2")
scope.Connect()
Dim objectQuery As New ObjectQuery("SELECT * FROM Win32_Processor")
Dim searcher As New ManagementObjectSearcher(scope, objectQuery)
Dim cpu As ManagementObject
For Each cpu In searcher.Get()
Console.WriteLine("Processor: " cpu("Name"))
Console.WriteLine("Manufacturer: " cpu("Manufacturer"))
Console.WriteLine("Clock frequency: " cpu("MaxClockSpeed") " MHz")
Console.WriteLine("NumberOfLogicalProcessors: " cpu("NumberOfLogicalProcessors"))
Console.WriteLine("NumberOfCores: " cpu("NumberOfCores"))
Console.WriteLine()
Next cpu
Console.WriteLine()
Console.WriteLine("Press any key to quit")
Console.ReadKey()
End Sub
End Module