How do I retrieve the version of a file from a batch file on Windows Vista?

前端 未结 7 1142
傲寒
傲寒 2020-12-05 14:39

Binary files have a version embedded in them - easy to display in Windows Explorer.

\"alt

How can I re

7条回答
  •  难免孤独
    2020-12-05 15:37

    Here is my try using WMIC to get file version of all *.exe and *.dll inside the directory of Skype as example :

    @echo off
    Mode 75,3 & color 9E
    Title Get File Version of any Program from file list using WMIC by Hackoo
    Set "RootFolder=%ProgramFiles%\Skype"
    @for %%a in (%RootFolder%) do set "FolderName=%%~na"
    Set "File_Version_List=%~dp0%FolderName%_File_Version_List.txt"
    Set "ErrorFile=%~dp0%FolderName%_Error.txt
    Set Extensions="*.exe" "*.dll"
    If exist "%ErrorFile%" Del "%ErrorFile%"
    If exist "%File_Version_List%" Del "%File_Version_List%"
    echo(
    echo          Please wait a while ... Process to get file version ...
    set "BuildLineWith=call :BuildLine "
    setlocal enabledelayedexpansion
    CD /D "%RootFolder%"
    @for /f "delims=" %%F in ('Dir /b /s %Extensions%') do (
        set "Version="
        Call :Get_AppName "%%F" AppName
        Call :Add_backSlash "%%F"
        Call :GetVersion !Application! Version
        Call :Remove_backSlash !Application!
        If defined Version (
            (
                echo !Application!
                echo !AppName! ==^> !Version!
                %BuildLineWith%*
            )>> "%File_Version_List%"
        ) else (
            (
                echo Version is not defined in !Application!
                %BuildLineWith%#
            )>> "%ErrorFile%"
        )
    )
    If Exist "%ErrorFile%" Start "" "%ErrorFile%"
    If Exist "%File_Version_List%" Start "" /MAX "%File_Version_List%" & Exit
    ::*******************************************************************
    :GetVersion  
    Rem The argument %~1 represente the full path of the application
    Rem without the double quotes
    Rem The argument %2 represente the variable to be set (in our case %2=Version)  
    FOR /F "tokens=2 delims==" %%I IN (
      'wmic datafile where "name='%~1'" get version /format:Textvaluelist 2^>^nul'
    ) DO FOR /F "delims=" %%A IN ("%%I") DO SET "%2=%%A"
    Exit /b
    ::*******************************************************************
    :Add_backSlash 
    Rem Subroutine to replace the simple "\" by a double "\\" into a String
    Set "Application=%1"
    Set "String=\"
    Set "NewString=\\"
    Call Set "Application=%%Application:%String%=%NewString%%%"
    Exit /b
    ::*******************************************************************
    :Remove_backSlash 
    Rem Subroutine to replace the double "\\" by a simple "\" into a String
    Set "Application=%1"
    Set "String=\\"
    Set "NewString=\"
    Call Set "Application=%%Application:%String%=%NewString%%%"
    Exit /b
    ::*******************************************************************
    :Get_AppName  
    Rem %1 = FullPath
    Rem %2 = AppName
    for %%i in (%1) do set "%2=%%~nxi"
    exit /b
    ::*******************************************************************
    :BuildLine
    set "LineChar=%1"
    if "%LineChar%"=="" set "LineChar=_"
    for /f "tokens=2 skip=4" %%A in ('mode con: /status') do set "WindowColumns=%%A" & goto :GotColumnCount
    :GotColumnCount
    set "CharLine="
    setlocal EnableDelayedExpansion
    for /L %%A in (1,1,%WindowColumns%) do set "CharLine=!CharLine!!LineChar:~0,1!"
    setlocal DisableDelayedExpansion
    endlocal
    echo %CharLine%
    goto :eof
    ::*******************************************************************
    

提交回复
热议问题