I maintain a script in our test harness that autodetects and reports back the OS version of the machine under test. I couldn't tell if I was running XP SP1 or XP SP2 - so I had a kludge that used spcheck from the reskit. But the real problem was that I was getting most info using ver from the cmd shell but on Windows 2000 couldn't tell the difference between Professional and Server. I was able to find all this info in the registry so I ripped out the hacks and now I'm just reading from there. If anyone else out there is trying to do the same thing, here's where I get the information from (all are in HKLM):
(Microsoft Windows Server 2003, Microsoft Windows XP, Microsoft Windows 2000)
(Service Pack 1, Service Pack 2, ...)
And to distinguish between Pro and Server on Windows 2000: SYSTEMCurrentControlSetControlProductOptionsProductType
I didn't actually use it in my case but if you're looking for more of a prepackaged tool to do this type of thing, DtWinVer at http://www.codeproject.com/system/dtwinver.asp also looks promising.