VB?我不熟,下面是用匯編寫(xiě)的,我運(yùn)行過(guò)可以的。
成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作,成都做網(wǎng)站公司-創(chuàng)新互聯(lián)已向上1000家企業(yè)提供了,網(wǎng)站設(shè)計(jì),網(wǎng)站制作,網(wǎng)絡(luò)營(yíng)銷(xiāo)等服務(wù)!設(shè)計(jì)與技術(shù)結(jié)合,多年網(wǎng)站推廣經(jīng)驗(yàn),合理的價(jià)格為您打造企業(yè)品質(zhì)網(wǎng)站。
//--------------------------------
.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
//-------------------------------------------------------
程序確實(shí)可以執(zhí)行,輸出CPU的ID等信息。
注意:DOS下或MS-DOS下使用。
使用wmi
類(lèi)“Win32_Processor”中LoadPercentage屬性為當(dāng)前的cpu使用率
示例代碼: Private Sub Timer1_Timer()
Dim WMI服務(wù) As Object
Dim 對(duì)象 As Object
Dim 子對(duì)象 As Object
Dim 電腦名 As String
Dim 刷新 As Long
刷新 = 0
電腦名 = "." '表示本地計(jì)算機(jī)
Set WMI服務(wù) = GetObject("winmgmts://" 電腦名 "/root/cimv2")
Set 對(duì)象 = WMI服務(wù).InstancesOf("Win32_Processor")
Me.CurrentX = 0
Me.CurrentY = 0
For Each 子對(duì)象 In 對(duì)象
If 刷新 = 0 Then
刷新 = 1
Me.Cls
End If
Me.Print 子對(duì)象.Name "[" 子對(duì)象.CurrentClockSpeed "Hz] 使用率:" _
子對(duì)象.LoadPercentage "%"
Next
End Sub
CPU位數(shù)獲取不了,核心數(shù)可以,能夠用程序偵測(cè)出的,可以點(diǎn)我的電腦,右鍵屬性
使用wmi
類(lèi)“Win32_Processor”中LoadPercentage屬性為當(dāng)前的cpu使用率
示例代碼: Private Sub Timer1_Timer()
Dim WMI服務(wù) As Object
Dim 對(duì)象 As Object
Dim 子對(duì)象 As Object
Dim 電腦名 As String
Dim 刷新 As Long
刷新 = 0
電腦名 = "." '表示本地計(jì)算機(jī)
Set WMI服務(wù) = GetObject("winmgmts://" 電腦名 "/root/cimv2")
Set 對(duì)象 = WMI服務(wù).InstancesOf("Win32_Processor")
Me.CurrentX = 0
Me.CurrentY = 0
For Each 子對(duì)象 In 對(duì)象
If 刷新 = 0 Then
刷新 = 1
Me.Cls
End If
Me.Print 子對(duì)象.Name "[" 子對(duì)象.CurrentClockSpeed "Hz] 使用率:" _
子對(duì)象.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