.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> System Process >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get Processor ID using C#

Posted By:Pankaj Mishra       Posted Date: August 11, 2008    Points: 10    Category: System Process    URL: http://www.dotnetspark.com  

using below code you can get Processor id or CPU id of the system using C# or Vb.NET

Get processor ID/CPU ID using Below code. sometime we need the Processor ID to perform some validation like trail time validation etc. So below is the static method which will give you CPU ID or Processor ID of the computer.

public static string GetProcessorID()

string sProcessorID = "";

string sQuery = "SELECT ProcessorId FROM Win32_Processor";

ManagementObjectSearcher oManagementObjectSearcher = new ManagementObjectSearcher(sQuery);

ManagementObjectCollection oCollection = oManagementObjectSearcher.Get();

foreach (ManagementObject oManagementObject in oCollection)


sProcessorID = (string)oManagementObject["ProcessorId"];


return (sProcessorID);

And the same above code in VB.Net

Public Shared Function GetProcessorID() As String
    Dim sProcessorID As String = ""
    Dim sQuery As String = "SELECT ProcessorId FROM Win32_Processor"
    Dim oManagementObjectSearcher As New ManagementObjectSearcher(sQuery)
    Dim oCollection As ManagementObjectCollection = oManagementObjectSearcher.[Get]()
    For Each oManagementObject As ManagementObject In oCollection
        sProcessorID = DirectCast(oManagementObject("ProcessorId"), String)
    Return (sProcessorID)
End Function

Make sure that you have added system.Management namespace and assembly



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend