Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Dear all,

can any one help me out in extracting system processor id in vb6.0,,
i used following code to extract but only for laptop this code is able to extract processor id but for the desktop it is unable to extract....
The code is as follows......................

PLZ send a solution

-------------------------------------------------------------------------
Public Function MBSerialNumber() As String

'RETRIEVES SERIAL NUMBER OF MOTHERBOARD
'IF THERE IS MORE THAN ONE MOTHERBOARD, THE SERIAL
'NUMBERS WILL BE DELIMITED BY COMMAS

'YOU MUST HAVE WMI INSTALLED AND A REFERENCE TO
'Microsoft WMI Scripting Library IS REQUIRED

Dim objs As Object

Dim obj As Object
Dim WMI As Object



Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_BaseBoard")
'Set objs = WMI.InstancesOf(WindowState)
For Each obj In objs
procid = procid & obj.SerialNumber
If procid < objs.Count Then procid = procid & ","
Next
MBSerialNumber = procid
procid = LTrim$(procid)
procid = RTrim$(procid)
MsgBox "Proc_id :" + procid
End Function


--------------------------------------------------------------------
Posted
Updated 9-Jan-10 9:50am
v2

Oh... please sorry, I've missed that you need a solution for VB6, not VB.NET. Here's example in VB:

VB
Function GetCpuID() 
  Dim wmi, cpu, cpuid
  Set wmi = GetObject("winmgmts:")
  For Each cpu in wmi.InstancesOf("Win32_Processor")
   cpuid = cpuid + cpu.ProcessorID     
  Next 
  MsgBox cpuid
End Function

Sorry if this will not compile, I've tested it using Microsoft VBScript and it works for me
 
Share this answer
 
Here's the solution:
C#
private static string GetCpuId() {
    string cpuinfo = string.Empty;

    ManagementObjectSearcher searcher = new ManagementObjectSearcher("select processorid from win32_processor");

    foreach (ManagementObject mo in searcher.Get()) {
        if (cpuinfo == string.Empty)
            cpuinfo = mo.Properties["processorid"].Value.ToString();
        else
            break;
    }
    return cpuinfo;
}


Sorry, that was C# code.
In VB.NET it will be:
VB
Private Shared Function GetCpuId() As String
    Dim cpuinfo As String = String.Empty
    
    Dim searcher As New ManagementObjectSearcher("select processorid from win32_processor")
    
    For Each mo As ManagementObject In searcher.[Get]()
        If cpuinfo = String.Empty Then
            cpuinfo = mo.Properties("processorid").Value.ToString()
        Else
            Exit For
        End If
    Next
    Return cpuinfo
End Function
 
Share this answer
 
v3
dear the solution wat u given is for vb.net....
but i want solution to be in vb6.0.........
 
Share this answer
 
Mr Dmitry Vitkovsky

Congratulations !!

Works fine !!

My best regard

if you need travel to Colombia
on near future, here you are welcome.

Eduardo Migneco
Bogota,Colombia
emigneco@yahoo.com
 
Share this answer
 
VB6 is obsolete, and was always rubbish. I can't fathom why anyone would use it today, apart from self loathing. Why are you using it ? I expect the best way to do this in VB6, is to write a C++ dll to do it, that's how VB6 always did it's heavy lifting.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900