I found a link with C# code that can do exactly this:
http://www.codeproject.com/csharp/ha...k_serialNo.asp
If you're looking for C/C++, not sure. Maybe something in it will still be helpful.
It seems, from the article, you'll need to use WMI for this. Maybe that's at least a pointer in the right general direction.