how to get cpu's id?

  • Thread starter Thread starter jay
  • Start date Start date
Hi,

Add a reference to system.management.dll

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Processor")

moReturn = moSearch.Get

For Each mo In moReturn

Debug.WriteLine(mo("Name"))

Debug.Indent()

Debug.WriteLine(mo("ProcessorID"))

Debug.Unindent()

Next

Ken
 
Hi

Here is the code. Watch out for line wraps

VB
Class WMClassLib_VB
Function CpuID()
Dim oWMI, oCpu
oWMI = GetObject("winmgmts:")
For Each oCpu In oWMI.InstancesOf
("Win32_Processor")
Console.WriteLine("CPU: " & oCpu.ProcessorID)
Next
End Function
End Class

C#(Add System.Management to References)
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Management;
namespace CPUIDUsingWMI_CSharpClassLib
{
public class WMClassLib_CSharp
{
public string GetCPUId()
{
string cpuInfo = String.Empty;
string temp=String.Empty;
ManagementClass mc = new ManagementClass
("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if(cpuInfo==String.Empty)
{// only return cpuInfo from first CPU
cpuInfo = mo.Properties["ProcessorId"].Value.ToString
();
}
}
return cpuInfo;
}
}
}

hth

regards,

sr
 
Hi:
it's ok and i want to know any other method but wmi.
Hi

Here is the code. Watch out for line wraps

VB
Class WMClassLib_VB
Function CpuID()
Dim oWMI, oCpu
oWMI = GetObject("winmgmts:")
For Each oCpu In oWMI.InstancesOf
("Win32_Processor")
Console.WriteLine("CPU: " & oCpu.ProcessorID)
Next
End Function
End Class

C#(Add System.Management to References)
using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Management;
namespace CPUIDUsingWMI_CSharpClassLib
{
public class WMClassLib_CSharp
{
public string GetCPUId()
{
string cpuInfo = String.Empty;
string temp=String.Empty;
ManagementClass mc = new ManagementClass
("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
if(cpuInfo==String.Empty)
{// only return cpuInfo from first CPU
cpuInfo = mo.Properties["ProcessorId"].Value.ToString
();
}
}
return cpuInfo;
}
}
}

hth

regards,

sr
-----Original Message-----


.
 
it's ok and i want to know any other method but wmi.

write a win32 library that makes use of cpuid instruction.
 
Back
Top