The easiest way is likely to call dmicode, redirect its output to a file and parse that from your program (the file can be temporary, deleted afterwards). The serial number could be handled like a password: hash it cryptographically and compare the result to a stored hash for the target platform.

I didn't find a good recommendation for more direct access. Closest matches are