How to get File version in variable using .cmd
I used wmic to get the version of a EXE stored in a variable. It works fine when I execute it from CMD (that I ran as Admin) but when executed either in a .cmd or .bat files (even when ran as admin) the variable is not populated. This works directly in CMD: set "npver="&for /F "tokens=2delims==" %a in ('wmic datafile where "Name='c:\\Windows\\System32\\notepad.exe'" get version /format:list') do set "npver=%a" When I created the .cmd file, I doubled the % signs. You forgot to echo the variable with the command echo %npver% With Command line : set "npver="&for /F "tokens=2delims==" %a in ('wmic