Crie uma classe chamada pCPU e adicione;
1: Imports System.Environment 2: Imports System.Management 3:
Public Class
pCPU 4:
'Retorna o numero de CPUs
5: ReadOnly Property Count() As String 6: Get 7: Return GetEnvironmentVariable("NUMBER_OF_PROCESSORS").ToString 8: End Get 9: End Property 10:
'Retorna se o sistema é 32 ou 64 bits
11: ReadOnly Property Architecture() As String 12: Get 13: Return GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").ToString 14: End Get 15: End Property 16:
'retorna o nivel do processador
17: ReadOnly Property Level() As String 18: Get 19: Return GetEnvironmentVariable("PROCESSOR_LEVEL").ToString 20: End Get 21: End Property 22:
'PEGA A TEMPERATURA DO PROCESSADOR
23: ReadOnly Property Temp() As String 24: Get 25: Try 26: Dim searcher As New ManagementObjectSearcher( _ 27: "root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature") 28: For Each queryObj As ManagementObject In searcher.Get() 29: Dim temperatura As Double = CDbl(queryObj("CurrentTemperature")) 30: temperatura = (temperatura - 2732) / 10.0 31: Return (temperatura.ToString) 32: Next 33: Catch err As ManagementException 34: Return ("Erro " & err.Message) 35: End Try 36: End Get 37: End Property 38:
'Pega o nome do processador
39: ReadOnly Property Processador() As String 40: Get 41: Try 42: Dim Nome As String 43: Nome = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\SYSTEM\CentralProcessor\1", "ProcessorNameString", Nothing) 44: Return Nome 45: Catch ex As Exception 46: MsgBox("Erro na leitura do Processador: " & ex.Message) 47: End Try 48: End Get 49: End Property 50:
'Retorna a velocidade do processador
51: ReadOnly Property Speed() As String 52: Get 53: Try 54: Dim Nome As String 55: Nome = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\SYSTEM\CentralProcessor\1", "ProcessorNameString", Nothing) 56: Dim Speeder As String = Right(Nome, 9) 57: Return Speeder 58: Catch ex As Exception 59: MsgBox("Erro na leitura da velocidade: " & ex.Message) 60: End Try 61: End Get 62: End Property 63: Private m_PerformanceCounter As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total") 64: ReadOnly Property CPUparce As String 65: Get 66: Dim S As String = CInt(m_PerformanceCounter.NextValue()) & "%" 67: Return S 68: End Get 69: End Property 70: End Class
Para chamar determinada função;
1: Dim Info As New NomeDoProjeto.pCPU
2: Textbox1.text = Info.Count
3: Textbox2.text = Info.Architecture
4: Textbox3.text = Info.Level
Caso queria saber também quanto % está sendo usando do CPU, Declare o segunte código abaixo do Public Class Form1;
1: Private UsoDaCPU As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total")
2: 'Para chamar a função
3: Textbox1.text = Clint(UsoDaCPU.NextValue() & "%")
0 comentários:
Postar um comentário