-2

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:

enter image description here

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!!!

Community
  • 1
  • 1
maxfax
  • 4,281
  • 12
  • 74
  • 120

1 Answers1

4

@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.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Ok, I will check the second option on many computers and let you know. Thanks! – maxfax Jul 29 '11 at 22:46
  • I have tested on 3 laptops. One with Windows 7 shows "Base Serial Number" instead of a normal number. Therefor 2 out of 5 machines retrieve the serial incorrectly. I cannot rely on this method. Is there other way? Thanks! – maxfax Jul 30 '11 at 06:19
  • @maxfax, the another method is read directly the `SMBIOS` tables and parse the information, check these WinApi functions `EnumSystemFirmwareTables` and `GetSystemFirmwareTable` http://msdn.microsoft.com/en-us/library/ms724379%28VS.85%29.aspx – RRUZ Jul 30 '11 at 07:45
  • If you don't mind, please gave an example how to use that function. Thanks! – maxfax Jul 30 '11 at 07:50
  • I am in a shock. What do those 2 cods do? One said me that the second option shows the same serial on 2 machines today!!! 2 motheboards are Asus, but one is R5, other is R4!!!! – maxfax Jul 31 '11 at 06:41
  • So the second option does not work completely or retrieves the same serials on 2 machines...Nobody says anything... Did not try? – maxfax Jul 31 '11 at 06:45