Retrieving Motherboard Information in VB6

هذه المقالة متوفرة أيضا باللغة العربية، اقرأها هنا.

In the early days, we have talked about how to retrieve motherboard information in C# and VB.NET. After receiving your feedbacks, we decided to extend it to include VB6 as well.

After all, we could write the following code snippet to get motherboard information in Visual Basic 6:

Set colProcessList = GetObject("Winmgmts:") _
    .ExecQuery("SELECT SerialNumber, Product FROM Win32_BaseBoard")

For Each objprocess In colProcessList
    MsgBox ("Serial Number=" & objprocess.SerialNumber)
    MsgBox ("Product=" & objprocess.Product)
Next

Feel free to contact us if you need any help.

Have a nice day!

Retrieving Motherboard Serial Number using WMI

هذه المقالة متوفرة أيضا باللغة العربية، اقرأها هنا.

A simple way to get system information is through Windows Management Instrumentation (WMI).

WMI was firstly introduced part of Windows 2000. It’s designed to help your system, applications, and networks.

WMI has amazing design; It’s implemented like a large database that contains several tables and types. And you can query it using SQL statements (really!).

.NET Framework includes a various classes for dealing with WMI. These classes reside on assembly System.Management that you can reference it into your project.

Querying WMI is very simple. First, create a ManagementObjectSearcher object that will hold the SQL query. Then you execute the query by calling the Get() method of the ManagementObjectSearcher object, returns a collection of ManagementObject objects. These object looks like rows in a database that you can access its columns -PropertyData objects- and retrieve its values.

In WMI tables called classes, rows called objects, and columns called properties.

The following example demonstrates how to get Motherboard information like its name and serial number:

// C# Code

// First we create the ManagementObjectSearcher that
// will hold the query used.
// The class Win32_BaseBoard (you can say table)
// contains the Motherboard information.
// We are querying about the properties (columns)
// Product and SerialNumber.
// You can replace these properties by
// an asterisk (*) to get all properties (columns).
ManagementObjectSearcher searcher =
    new ManagementObjectSearcher
    ("SELECT Product, SerialNumber FROM Win32_BaseBoard");

// Executing the query...
// Because the machine has a single Motherborad,
// then a single object (row) returned.
ManagementObjectCollection information = searcher.Get();
foreach (ManagementObject obj in information)
{
    // Retrieving the properties (columns)
    // Writing column name then its value
    foreach (PropertyData data in obj.Properties)
        Console.WriteLine("{0} = {1}", data.Name, data.Value);
    Console.WriteLine();
}

// For typical use of disposable objects
// enclose it in a using statement instead.
searcher.Dispose();
' VB.NET Code

' First we create the ManagementObjectSearcher that
' will hold the query used.
' The class Win32_BaseBoard (you can say table)
' contains the Motherboard information.
' We are querying about the properties (columns)
' Product and SerialNumber.
' You can replace these properties by
' an asterisk (*) to get all properties (columns).
Dim searcher As New ManagementObjectSearcher _
    ("SELECT Product, SerialNumber FROM Win32_BaseBoard")

' Executing the query...
' Because the machine has a single Motherborad,
' then a single object (row) returned.
Dim information As ManagementObjectCollection = searcher.Get()
For Each obj As ManagementObject In information
' Retrieving the properties (columns)
' Writing column name then its value
    For Each data As PropertyData In obj.Properties
        Console.WriteLine("{0} = {1}", data.Name, data.Value)
    Next
    Console.WriteLine()
Next

' For typical use of disposable objects
' enclose it in a using statement instead.
searcher.Dispose()
' VB6
Set colProcessList = GetObject("Winmgmts:") _
    .ExecQuery("SELECT SerialNumber, Product FROM Win32_BaseBoard")

For Each objprocess In colProcessList
    MsgBox ("Serial Number=" & objprocess.SerialNumber)
    MsgBox ("Product=" & objprocess.Product)
Next

To read more about WMI and get lists of classes and features that it supports, see WMI Reference.

A long time ago, I used that mechanism to protect my application from copying it from a PC to another. The application asks the user for the serial number if he changed his PC (frankly, Motherboard). Did you validate? The serial number itself is an encrypted hash of the Motherboard serial number!

Visual Basic 6.0 to be Supported on Windows 7

Contrary to widely circulated rumors, Visual Basic 6.0 will ship and will be supported on Windows 7 for the lifetime of the OS. Microsoft has released an updated support statement detailing the exact nature of ongoing support.

The Visual Basic team is committed to “It Just Works” compatibility for Visual Basic 6.0 applications on Windows Vista, Windows Server 2008 and Windows 7. The Visual Basic team’s goal is that Visual Basic 6.0 applications that run on Windows XP will also run on Windows Vista, Windows Server 2008 and Windows 7.

The Visual Basic team is also committed to the Visual Basic 6.0 development environment running on Windows Vista, Windows Server 2008 and Windows 7.

As detailed in the support document, the core Visual Basic 6.0 runtime will be supported for the full lifetime of Windows Vista, Windows Server 2008 and Windows 7, which is five years of mainstream support followed by five years of extended support, per the standard support agreement.

The support statement addresses Windows 7 directly:

Since the initial release of this support statement, the Windows 7 operating system has been announced. This document has been updated to clarify Microsoft’s support for VB6 on Windows 7.

VB6 runtime will ship and will be supported in Windows 7 for the lifetime of the OS. Developers can think of the support story for Vista being the same as it is for Windows 7. However there are no plans to include VB6 runtime in future versions of Windows beyond Windows 7.

Source- InfoQ