It is as easy as checking
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SystemInformation\SystemProductName to see if it contains the string
Virtual. There are also some other system call tricks, like revealing if the OS is a Server Core, located
here.
It looks like, if you wanted to, you could gather most of the information with PowerShell too. It looks pretty straightforward.