There are 2 good examples how to get a serial number: How to get motherboard id or serial number in Delphi?
All they work for me (Windows 7). But for 2 people they don't!
The Option 1 (Microsoft WMIScripting Library) returns an error which cannot be handled in an exception! (I tried to use my code in the exception but it was not performed). OS Windows 7:
The Option 2 (Windows XP) - returns nothing: no errors, no the serial number.
Can anybody explain why it is and is there a work code to do this?
There is a comment in that link: "@PRUZ And you know something about my second comment? that I check the same code in some other computer which returns 'none'. What's the matter with it? – Himadri"
Thanks!!!
@maxfax, the first sample code does not work in Windows xp because uses the ItemIndex
property which is available since windows vista for more details check this article (Be careful when you import the Microsoft WMIScripting Library
). the second snippet must work ok in any Windows system, because access the WMI properties using the name of the property directly. Now if the second option does not retrieve a serial number in any machine just is because the WMI provider does not expose information for this property. as side note some Virtual Machines like VMWARE reports None
as serial number .
Update
I just wrote an article on my blog about how read the SMBios (Reading the SMBios Tables using Delphi
), using this method you get the serial number of the motherboard directly from the SMBios tables.