Reputation: 11314
I am checking for the OS version using command prompt.
I am using following code to get the version number
systeminfo | findstr /B /c:"OS Version"
OS Version: 5.2.3790 Service Pack 2 Build 3790
OS Version: 6.1.7601 Service Pack 1 Build 7601
But I am not sure how can I have Major version number (First digit of version)
How can I get the major version number OR
If can I check if the version numbers first char is 5 OR 6
Upvotes: 2
Views: 3771
Reputation: 130819
I would use the ver
command instead of systeminfo
. My Windows 7 machine reports:
Microsoft Windows [Version 6.1.7601]
The following batch script snippet will define a variable containing the primary version number:
for /f "tokens=2 delims=[]" %%A in ('ver') do for /f "tokens=2 delims=. " %%B in ("%%A") do set "majorVersion=%%B"
Upvotes: 1
Reputation: 45771
You could pipe the output again through FINDSTR, for example:
systeminfo | findstr /B /c:"OS Version" | findstr /c:" 6."
And then check the ERRORLEVEL returned to see if 6.
was present in the returned string.
NOTE:
System.Environment.OSVersion
property and sets an error level for you as this would be string parse-free (and thus a lot less likely to break)!Upvotes: 2
Reputation: 26140
here is a snippet using ver.exe :
for /f "tokens=4 delims=. " %%i in ('ver') do set majorversion=%%i
Upvotes: 1