If you need to get installed windows version and service pack name from command line use following command.
C:\>systeminfo | findstr /B /C:”OS Name” /C:”OS Version”
Then you will see output as follows
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600