Is the hard-drive serial number with WMIService CHANGEABLE?

Viewed 161

I use Hard-Drive Serial-Number check to register my products.

But I see that sometimes it's being changed. Just 2 weeks after the client has activated the product, the hard-drive Serial-Num changed.

Is this property changeable? and if so, how when and why is it changed?

Here is the code i use in VB:

Dim WMIService As Object, Items As Object, SubItems As Object, temp
    
Set WMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
    Set Items = WMIService.ExecQuery("Select * from Win32_PhysicalMedia", , 48)
    For Each SubItems In Items
        temp = SubItems.SerialNumber
        If LenB(temp) Then Exit For
    Next

and the same thing i use in C#

using System.Management;

public string GetHDDSerial()
{
    ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

    foreach (ManagementObject wmi_HD in searcher.Get())
    {
        // get the hardware serial no.
        if (wmi_HD["SerialNumber"] != null)
            return wmi_HD["SerialNumber"].ToString();
    }

    return string.Empty;
}
1 Answers

Thanks to the comment from FunThomas and after a little troubleshooting with my client, i found out that he is using sometimes an external drive for more space, and when the external drive is plugged in - i'm getting a different HDD Serial-number.

Now i have figured how to get the serial number from the current drive letter.

here is the code for VB:

Dim WMIService As Object, DiskDrives As Object, Drive As Object, DiskPartitions As Object, Partition As Object, SerialNumber, currentDrive
currentDrive = Environ("HomeDrive")
Set WMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set DiskPartitions = WMIService.ExecQuery("ASSOCIATORS OF {Win32_LogicalDisk.DeviceID='" & currentDrive & "'} WHERE ResultClass=Win32_DiskPartition")

For Each Partition In DiskPartitions
Set DiskDrives = WMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" & Partition.DeviceID & "'} WHERE ResultClass=Win32_DiskDrive")
    For Each Drive In DiskDrives
        Debug.Print "Caption: " & Drive.Caption, "Description: " & Drive.Description, "Name: " & Drive.Name, "Model: " & Drive.Model, "SerialNumber: " & Drive.SerialNumber
        SerialNumber = Drive.SerialNumber
    Next
Next
Related