Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

This will return the CPU serial number.

Imports System.Management

Dim sysID As String = String.Empty
Dim manClass As New ManagementClass("Win32_Processor")
Dim mObjCol As ManagementObjectCollection = manClass.GetInstances
Dim m As ManagementObject

For Each m In mObjCol
   If sysID = "" Then
       sysID = m.Properties("ProcessorId").Value
       Exit For
   End If
Next
MessageBox.Show(sysID)

Hope this helps.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted
You'll need to add a reference to the System.Management dll. From the VS IDE's main menu select Project | Add Reference | .NET tab | System.Management.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Thanks. I thought having "System" available made everything within it available, but I guess not. Interesting that even though mObjCol is a ManagementObjectCollection, that I couldn't access the first element directly, which is why I'm guessing you made the loop. Is there any particular reason this object is set up that way?

 

Thanks again.

  • *Experts*
Posted
I'm just guessing, but the Management Object Collection is probably setup this way to allow for various combinations and quantities of processors within a single computer. I used a loop because I only needed the first processor as a reference.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
I thought having "System" available made everything within it available

 

No - Namespaces simply declare a hierachy, similar to a directory structure scenario, in that even though you specify System (namespace), it only provides access to the Classes within that namespace, and not to any sub-namespaces. It's very much like the With statement from VB6, allowing you to act upon that particular level (of an object/class within VB6, but Namespace within .NET)

 

 

Paul.

  • Leaders
Posted
Also, different libraries can define classes in the same dlls. You can reference System.Windows.Forms.dll but there still may be classes in System.Windows.Forms that you cannot access because they are defined in System.Design.Dll (not sure that that is true, but it is just an example).
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...