I'm basically trying to get a consistent hard disk Serial Number using WMI. At the moment I'm using the code below which start a loop then exits after the first one.
My question is firstly, is the primary hard disk always returned as the first drive? If so, the way I'm doing it should be fine for my requirements.
If not, how do I get the serial number of the Windows System drive. I can get the drive letter easily enough, I just need to know how to use WMI to get the WMI_PhysicalMedia item from a drive letter.
Hope that makes sense. Cheers for your help.
Public Function GetDiskSerial() As String
Dim WMI As Object
Dim wmiCollection As Object
Dim wmiMember As Object
'Get the WMI Object
Set WMI = GetObject("winmgmts:\\")
'Get a collection of drives
Set wmiCollection = WMI.InstancesOf("Win32_PhysicalMedia")
For Each wmiMember In wmiCollection
GetDiskSerial = Trim(wmiMember.SerialNumber)
Set wmiMember = Nothing
Set wmiCollection = Nothing
Set WMI = Nothing