Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting Processsor ID without ManagementClass

Getting Processsor ID without ManagementClass

Scheduled Pinned Locked Moved C#
csharpdotnetcomtutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrEyes
    wrote on last edited by
    #1

    Hello all, The following code will retrieve a unique processor ID (for the first processor) using the .NET Frameworks System.Management.ManagementClass class:

    public static string GetCPUId()
    {
    string cpuInfo = string.Empty;

    ManagementClass mgr = new ManagementClass("Win32\_Processor");
    ManagementObjectCollection mgrCollection = mgr.GetInstances();
    
    foreach (ManagementObject mgrItem in mgrCollection)
    {
        if (cpuInfo == string.Empty)
        {
            cpuInfo = mgrItem.Properties\["ProcessorId"\].Value.ToString();
            break;
        }
    }
    
    return cpuInfo;
    

    }

    However I need to do the same thing using DllImport/Interop. Does anybody know how to do this?

    L 1 Reply Last reply
    0
    • M MrEyes

      Hello all, The following code will retrieve a unique processor ID (for the first processor) using the .NET Frameworks System.Management.ManagementClass class:

      public static string GetCPUId()
      {
      string cpuInfo = string.Empty;

      ManagementClass mgr = new ManagementClass("Win32\_Processor");
      ManagementObjectCollection mgrCollection = mgr.GetInstances();
      
      foreach (ManagementObject mgrItem in mgrCollection)
      {
          if (cpuInfo == string.Empty)
          {
              cpuInfo = mgrItem.Properties\["ProcessorId"\].Value.ToString();
              break;
          }
      }
      
      return cpuInfo;
      

      }

      However I need to do the same thing using DllImport/Interop. Does anybody know how to do this?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      MrEyes wrote:

      The following code will retrieve a unique processor ID

      According to this web page[^] the processorID is not unique at all. You are confusing with the processor serial number which might be available through the UniqueID field of WMI, but this feature may be absent or disabled (in which case WMI returns a null value). The default state is: disabled. To access such features without WMI you need low-level code, say C + assembly, that executes the CPUID instruction and returns some register values; plus of course the necessary P/Invoke stuff to interface to the native code. For more info on CPUID, search for "Intel CPUID" and you will find utilities and documentation (Intel App Note 485). :)

      Luc Pattyn [My Articles] [Forum Guidelines]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups