Batch Script Check File Version

Posted on by
Check File BoxBatch Script Check File Version

I need to get the OS version with a batch file. I 've seen a lot of examples online, many uses something like this code: @echo off ver find 'XP' >nul if%ERRORLEVEL% == 0 goto ver_xp if not exist%SystemRoot% system32 systeminfo.exe goto warnthenexit systeminfo find 'OS Name' >%TEMP% osname.txt FOR /F 'usebackq delims=: tokens=2'%%i IN (%TEMP% osname.txt) DO set vers=%%i echo%vers% find 'Windows 7' >nul if%ERRORLEVEL% == 0 goto ver_7 echo%vers% find 'Windows Vista' >nul if%ERRORLEVEL% == 0 goto ver_vista goto warnthenexit:ver_7:Run Windows 7 specific commands here. Echo Windows 7 goto exit:ver_vista:Run Windows Vista specific commands here.

Checking file properties in a batch script? Honda Fit Jazz Ge6 here. 'Product version' field. How to loop though sub folder to check if folder is empty - batch script? Here is an example how you can pipe output of a vbscript check version to the batch command line: Set wshshell = CreateObject('WScript.Shell') Set filesys = CreateObject('Scripting.FileSystemObject') on error resume next. Check OS version through batch file. As you can see the script's cchecking for version is succh an old feature. Check my posted solution to see.

If you want a simple solution you can use the following script filever.vbs. It takes one input the name of the file and outputs the version of the file. If the files doesn't exist or you don't specify a file name it doesn't output anything. Set fso = WScript.CreateObject('Scripting.FileSystemObject') Set objArgs = WScript.Arguments.

Echo Windows Vista goto exit:ver_xp:Run Windows XP specific commands here. Echo Windows XP goto exit:warnthenexit echo Machine undetermined.:exit The problem is when I execute this on Vista or Windows 7 I get the message Machine undetermined Is there any other way to do what I want? It's much easier (and faster) to get this information by only parsing the output of ver: @echo off setlocal for /f 'tokens=4-5 delims=. '%%i in ('ver') do set VERSION=%%i.%%j if '%version%' == '6.3' echo Windows 8.1 if '%version%' == '6.2' echo Windows 8. If '%version%' == '6. Download Cisco Router Ios Image Gns3 Tutorial. 1' echo Windows 7. If '%version%' == '6.0' echo Windows Vista. Rem etc etc endlocal on MSDN documents which version number corresponds to which Windows product version (this is where you get the 6.1 means Windows 7 information from).

The only drawback of this technique is that it cannot distinguish between the equivalent server and consumer versions of Windows. These one-line commands have been tested on Windows XP, Server 2012, 7 and 10 (thank you ). Extract version x.y in a cmd console for /f 'tokens=4-7 delims=[.] '%i in ('ver') do @(if%i==Version (echo%j.%k) else (echo%i.%j)) Extract the full version x.y.z for /f 'tokens=4-7 delims=[.] '%i in ('ver') do @(if%i==Version (echo%j.%k.%l) else (echo%i.%j.%k)) In a batch script use%% instead of single% @echo off for /f 'tokens=4-7 delims=[.] '%%i in ('ver') do (if%%i==Version (set v=%%j.%%k) else (set v=%%i.%%j)) echo%v% Version is not always consistent to brand name number Be aware that the extracted version number does not always corresponds to the Windows name release. See below an extract from the.

10.0 Windows 10 6. Raveonettes In And Out Of Control Rarlab. 3 Windows Server 2012 6.3 Windows 8.1 /! 6.2 Windows 8 /! 6.1 Windows 7 /! 6.0 Windows Vista 5.2 Windows XP x64 5.1 Windows XP 5.0 Windows 2000 4.10 Windows 98 Please also up-vote answers from and as my answer is inspired from their ideas. Actually, that one liner doesn't work for windows xp since the ver contains xp in the string. Instead of 5.1 which you want, you would get [Version.5 because of the added token. I modified the command to look like this: for /f 'tokens=4-6 delims=[.

'%%i in ('ver') do set VERSION=%%i.%%j This will output Version.5 for xp systems which you can use to indentify said system inside a batch file. Sadly, this means the command cannot differentiate between 32bit and 64bit build since it doesn't read the.2 from 5.2 that denotes 64bit XP. You could make it assign%%k that token but doing so would make this script not detect windows vista, 7, or 8 properly as they have one token less in their ver string. Hope this helps! The first line forces a WMI console installation if required on a new build.

WMI always returns a consistent string of 'Version=x.x.xxxx' so the token parsing is always the same for all Windows versions. Parsing from the VER output has variable text preceding the version info, making token positions random. Delimiters are only the '=' and '.' The batch addition allows me to easily check versions as '510' (XP) up to '10000' for Win10.

I don't use the Build value. Setlocal EnableDelayedExpansion wmic os get version /value 1>nul 2>nul if%errorlevel% equ 0 ( for /F 'tokens=2,3,4 delims==.' %%A In ('wmic os get version /value') Do ( (Set /A '_MAJ=%%A') (Set /A '_MIN=%%B') (Set /A '_BLD=%%C') ) (Set /A '_OSVERSION=!_MAJ!*100') (Set /A '_OSVERSION+=!_MIN!*10') ) endlocal.