1

I am using the below vb6 code to get the currently running cpu id

     Dim CpuId As String
     Dim objWMIService, colItems, objItem

     Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
     Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")

     For Each objItem In colItems
     CpuId = objItem.ProcessorId

     Next

     msgbox cpuid

This works well for a single cpu processor. But many computers nowadays are having multiple processors, dual core, core i 3 etc. How can i list all the existing processor ids.

I am using the processor id to make licensing for my software and when the client computers swicthes the processor to the one i have not registered, the licensed machine is being declared unlicensed.

2
  • 1
    I would expect there is one CPU ID per physical processor. I would not expect to see one per core. You can only find out the number of cores in one processor (see the NumberOfCores property). Commented Oct 5, 2014 at 7:18
  • I would not expect to see one per core... i could be wrong but apparently the cpu id does change in multiple core scenario. And then i have to wait for the customer to call me so as to register them for the other cpu-id. I hope an experienced person can clarify for me. Commented Oct 6, 2014 at 0:02

1 Answer 1

1

The query you're using should get all the physical processors on the machine. If your software is truly installed on a multi-processor machine you could always register all processor IDs. Otherwise a quick experiment returns a single processor ID on my dual core laptop.

MSDN ProcessorID documentation:

ProcessorId

Data type: string
Access type: Read-only

Processor information that describes the processor features.

For an x86 class CPU, the field format depends on the processor support of the CPUID instruction. If the instruction is supported, the property contains 2 (two) DWORD formatted values. The first is an offset of 08h-0Bh, which is the EAX value that a CPUID instruction returns with input EAX set to 1. The second is an offset of 0Ch-0Fh, which is the EDX value that the instruction returns. Only the first two bytes of the property are significant and contain the contents of the DX register at CPU reset—all others are set to 0 (zero), and the contents are in DWORD format.

Private Sub GetInformation()
    Dim CpuId As String
    Dim objWMIService, colItems, objItem

    List1.Clear
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")

    'this loop runs once for each physical processor
    For Each objItem In colItems
        List1.AddItem "Processor description: " & objItem.Description
        List1.AddItem "Processor name: " & objItem.Name
        List1.AddItem "Processor ID: " & objItem.ProcessorId
        List1.AddItem "Device ID: " & objItem.DeviceID
        List1.AddItem "Unique ID: " & objItem.UniqueId
        List1.AddItem "Number of cores: " & objItem.NumberOfCores
        List1.AddItem "Number if Logical processors: " & objItem.NumberOfLogicalProcessors
    Next

End Sub

Result:

Result

If you don't already have it, the Win23_Processor class documentation can be found here. http://msdn.microsoft.com/en-us/library/aa394373%28VS.85%29.aspx

Sign up to request clarification or add additional context in comments.

3 Comments

I appreciate this. The only thing is there is another processor ID besides the one showing of BFEBFBFF000010676 in your laptop. I am hoping there is a code or some way of knowing from the start what that processor id is. Question is how do we loop for the other processor?
@webzy I believe you are mistaken. It appears to be 1 processor, with 1 ID and 2 (in this case), cores.
Thank you. The source of my multiple ids seem to have been coming from another source.... reading the disk drive ids to make a composite id...."Select * from Win32_physicalMedia". Your answer helped me to check my coding better.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.