Narzędzie wiersza poleceń do zrzutu wersji DLL systemu Windows?

Potrzebuję narzędzia wiersza poleceń, aby zrzucić standardowe informacje o wersji DLL systemu Windows, aby móc je przetworzyć za pomocą skryptu bash (Cygwin).

Jako programista Java nie jestem przyzwyczajony do narzędzi programistycznych Microsoftu (choć mam trochę doświadczenia z Microsoft Visual Embedded C++ 4.0 i Microsoft Visual Basic 6.0).

Odpowiednim narzędziem wydaje się być mt.exe, Jak podano na SO. Jednak jedyną szansą, jaką znalazłem, aby uzyskać to małe podanie, jest Pobierz ISO 1,29 GB z Windows SDK dla Windows Server 2008 i. NET Framework . Nie mogę uwierzyć, że to jedyny sposób, aby to zrobić.

Znalazłem też w Internecie małą aplikację o nazwie PEView, ale wyświetla zbyt wiele (i bezużytecznych w moim przypadku) informacji i nie jest to aplikacja wiersza poleceń.

Standard objdump dołączony do Cygwina może również zrzucić niektóre informacje o plikach DLL, ale nie widzę opcji zrzucenia DLL wersja. Zauważ, że MajorImageVersion, MinorImageVersion i inne pola wyrzucane przez to narzędzie (z opcją-p) nie są powiązane z własną wersją DLL.

Jakieś alternatywy co robić? Może przegapiłem jakąś ważną opcję objdump? Is mt.exe moim jedynym wyborem? Jeśli tak jest, czy można go uzyskać oddzielnie od Windows SDK?

Author: Community, 2009-03-02

11 answers

Możesz również spojrzeć na filever.exe, który można pobrać w ramach pakietu Windows XP SP2 Support Tools - tylko 4,7 MB do pobrania.

 9
Author: Franci Penov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-16 18:04:02

Możesz użyć PowerShell, aby uzyskać informacje, które chcesz.

(Get-Item C:\Path\To\MyFile.dll).VersionInfo

Domyślnie wyświetli ProductVersion i FileVersion Ale dostępna jest pełna wersja VERSIONINFO . Czyli zwracać Komentarze

(Get-Item C:\Path\To\MyFile.dll).VersionInfo.Comments
 90
Author: Graham Ambrose,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-29 09:01:17

Użyj Microsoft SysInternals Sigcheck . Ta próbka wyświetla tylko wersję:

sigcheck -q -n foo.dll

Rozpakowany sigcheck.exe to tylko 228 KB.

 56
Author: Alessandro Jacopson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-25 09:59:15

Możesz napisać skrypt VBScript, aby uzyskać informacje o wersji pliku:

VersionInfo.vbs

set args = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Echo fso.GetFileVersion(args(0))
Wscript.Quit

Możesz wywołać to z linii poleceń w następujący sposób:

cscript //nologo VersionInfo.vbs C:\Path\To\MyFile.dll
 45
Author: Patrick Cuff,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-03-02 22:52:23

Albo sam sobie zbudujesz. Otwórz VS, Utwórz nową aplikację konsolową. Utwórz prosty projekt bez obsługi ATL lub MFC, pozostaw zaznaczoną opcję stdafx, ale nie zaznaczaj "pusty projekt" i nazwij go VersionInfo.

Otrzymasz prosty projekt z 2 plikami: VersionInfo.cpp i VersionInfo.h

Otwórz plik cpp i wklej do niego następujące elementy, a następnie skompiluj. Będziesz mógł go uruchomić, pierwszy argument to pełna nazwa pliku, wyświetli się " Produkt: plik 5.6.7.8: 1.2.3.4 " w oparciu o Blok zasobów wersji. Jeśli nie ma zasobów wersji, zwróci -1, w przeciwnym razie 0.

Kompiluje do pliku binarnego 8K za pomocą DLL CRT, 60k ze wszystkim, co jest połączone statycznie (ustawione w opcjach C++, zmień "stronę generowania kodu, opcje Runtime" na "/MT")

HTH.

PS. Jeśli nie chcesz używać Visual Studio, to i tak będzie kompilowane przy użyciu dowolnego kompilatora c++ (trzymam kciuki), ale prawie na pewno będziesz musiał zmienić # pragma - wystarczy podać ten lib w Ustawieniach linkera pragma jest tylko skrótem do automatycznego łączenia się z tą biblioteką.


// VersionInfo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#pragma comment(lib, "version.lib")

int _tmain(int argc, _TCHAR* argv[])
{
    DWORD handle = 0;
    DWORD size = GetFileVersionInfoSize(argv[1], &handle);
    BYTE* versionInfo = new BYTE[size];
    if (!GetFileVersionInfo(argv[1], handle, size, versionInfo))
    {
        delete[] versionInfo;
        return -1;
    }
    // we have version information
    UINT    len = 0;
    VS_FIXEDFILEINFO*   vsfi = NULL;
    VerQueryValue(versionInfo, L"\\", (void**)&vsfi, &len);

    WORD fVersion[4], pVersion[4];
    fVersion[0] = HIWORD(vsfi->dwFileVersionMS);
    fVersion[1] = LOWORD(vsfi->dwFileVersionMS);
    fVersion[2] = HIWORD(vsfi->dwFileVersionLS);
    fVersion[3] = LOWORD(vsfi->dwFileVersionLS);
    pVersion[0] = HIWORD(vsfi->dwProductVersionMS);
    pVersion[1] = LOWORD(vsfi->dwProductVersionMS);
    pVersion[2] = HIWORD(vsfi->dwProductVersionLS);
    pVersion[3] = LOWORD(vsfi->dwProductVersionLS);

    printf("Product: %d.%d.%d.%d File: %d.%d.%d.%d\n", 
        pVersion[0], pVersion[1], 
        pVersion[2], pVersion[3], 
        fVersion[0], fVersion[1], 
        fVersion[2], fVersion[3]);
    delete[] versionInfo;

    return 0;
}
 10
Author: gbjbaanb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-03-02 23:25:57
C:\>wmic datafile where name="C:\\Windows\\System32\\kernel32.dll" get version
Version
6.1.7601.18229
 9
Author: bdimych,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-04 19:44:50

Lista narzędzi z Systernals może wykonać zadanie: http://technet.microsoft.com/en-us/sysinternals/bb896656.aspx

listdlls -v -d mylib.dll
 3
Author: Alex,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-12 08:03:12

Ta funkcja zwraca Szczegóły pliku NTFS Windows dla dowolnego pliku używającego Cygwin bash (rzeczywista r-click-properties-info) do wyrażenia

Przekazuje ścieżkę do finfo (), może być ścieżką unix, ścieżką dos, względną lub absolutną. Plik jest konwertowany do bezwzględnej ścieżki nix, a następnie sprawdzany, aby sprawdzić, czy w rzeczywistości jest zwykłym/istniejącym plikiem. Następnie przekonwertowany do bezwzględnej ścieżki windows i wysłany do "wmic". Następnie magic, masz Szczegóły pliku windows bezpośrednio w terminalu. Zastosowanie: cygwin, cygpath, sed, i awk. Potrzebuje Windows WMI " wmic.exe " do działania. Wyjście jest korygowane na łatwe...

$ finfo notepad.exe
$ finfo "C:\windows\system32\notepad.exe" 
$ finfo /cygdrive/c/Windows/System32/notepad.exe 
$ finfo "/cygdrive/c/Program Files/notepad.exe"
$ finfo ../notepad.exe

finfo() {
    [[ -e "$(cygpath -wa "$@")" ]] || { echo "bad-file"; return 1; }
    echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")" | sed 's/\\/\\\\/g')"\" get /value)" |\
    sed 's/\r//g;s/^M$//;/^$/d' | awk -F"=" '{print $1"=""\033[1m"$2"\033[0m" }'
}
 3
Author: jonretting,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-21 05:54:43

W CodeProject znajduje się aplikacja wiersza poleceń o nazwie "ShowVer":

ShowVer.exe command-line VERSIONINFO display program

Jak zwykle aplikacja jest dostarczana z exe i kodem źródłowym (VisualC++ 6).

Out wyświetla wszystkie dostępne metadane:

Na niemieckim systemie Win7 wyjście dla user32.dll wygląda tak:

VERSIONINFO for file "C:\Windows\system32\user32.dll":  (type:0)
  Signature:       feef04bd
  StrucVersion:    1.0
  FileVersion:     6.1.7601.17514
  ProductVersion:  6.1.7601.17514
  FileFlagsMask:   0x3f
  FileFlags:       0
  FileOS:          VOS_NT_WINDOWS32
  FileType:        VFT_DLL
  FileDate:        0.0
 LangID: 040704B0
  CompanyName       : Microsoft Corporation
  FileDescription   : Multi-User Windows USER API Client DLL
  FileVersion       : 6.1.7601.17514 (win7sp1_rtm.101119-1850)
  InternalName      : user32
  LegalCopyright    : ® Microsoft Corporation. Alle Rechte vorbehalten.
  OriginalFilename  : user32
  ProductName       : Betriebssystem Microsoft« Windows«
  ProductVersion    : 6.1.7601.17514
 Translation: 040704b0
 1
Author: Robert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-12 14:45:12

Za pomocą Powershell można uzyskać tylko ciąg wersji, tj. 2.3.4 z dowolnego dll lub exe za pomocą następującego polecenia

(Get-Item "C:\program files\OpenVPN\bin\openvpn.exe").VersionInfo.ProductVersion

Testowane na Windows 10

 1
Author: P. Lion,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-07 09:35:14

I w jedną stronę z makecab:

; @echo off
;;goto :end_help
;;setlocal DsiableDelayedExpansion
;;;
;;;
;;; fileinf /l list of full file paths separated with ;
;;; fileinf /f text file with a list of files to be processed ( one on each line )
;;; fileinf /? prints the help
;;;
;;:end_help

; REM Creating a Newline variable (the two blank lines are required!)
; set NLM=^


; set NL=^^^%NLM%%NLM%^%NLM%%NLM%
; if "%~1" equ "/?" type "%~f0" | find ";;;" | find /v "find" && exit /b 0
; if "%~2" equ "" type "%~f0" | find ";;;" | find /v "find" && exit /b 0
; setlocal enableDelayedExpansion
; if "%~1" equ "/l" (
;  set "_files=%~2"
;  echo !_files:;=%NL%!>"%TEMP%\file.paths"
;  set _process_file="%TEMP%\file.paths"
;  goto :get_info
; )

; if "%~1" equ "/f" if exist "%~2" (
;  set _process_file="%~2"
;  goto :get_info
; )

; echo incorect parameters & exit /b 1
; :get_info
; set "file_info="

; makecab /d InfFileName=%TEMP%\file.inf /d "DiskDirectory1=%TEMP%" /f "%~f0"  /f %_process_file% /v0>nul

; for /f "usebackq skip=4 delims=" %%f in ("%TEMP%\file.inf") do (
;  set "file_info=%%f"
;  echo !file_info:,=%nl%!
; )

; endlocal
;endlocal
; del /q /f %TEMP%\file.inf 2>nul
; del /q /f %TEMP%\file.path 2>nul
; exit /b 0

.set DoNotCopyFiles=on
.set DestinationDir=;
.set RptFileName=nul
.set InfFooter=;
.set InfHeader=;
.Set ChecksumWidth=8
.Set InfDiskLineFormat=;
.Set Cabinet=off
.Set Compress=off
.Set GenerateInf=ON
.Set InfDiskHeader=;
.Set InfFileHeader=;
.set InfCabinetHeader=;
.Set InfFileLineFormat=",file:*file*,date:*date*,size:*size*,csum:*csum*,time:*time*,vern:*ver*,vers:*vers*,lang:*lang*"

Przykładowe wyjście (ma wersję string, która jest małym dodatkiem do metody wmic:)):

c:> fileinfo.bat /l C:\install.exe
    file:install.exe
    date:11/07/07
    size:562688
    csum:380ef239
    time:07:03:18a
    vern:9.0.21022.8
    vers:9.0.21022.8 built by: RTM
    lang:1033

I jeszcze jeden za pomocą shell.zastosowanie i hybrid batch\jscript.Oto tooptipInfo.bat :

@if (@X)==(@Y) @end /* JScript comment
    @echo off

    rem :: the first argument is the script name as it will be used for proper help message
    cscript //E:JScript //nologo "%~f0" %*

    exit /b %errorlevel%

@if (@X)==(@Y) @end JScript comment */

////// 
FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
if (ARGS.Length < 1 ) {
 WScript.Echo("No file passed");
 WScript.Quit(1);
}
var filename=ARGS.Item(0);
var objShell=new ActiveXObject("Shell.Application");
/////


//fso
ExistsItem = function (path) {
    return FSOObj.FolderExists(path)||FSOObj.FileExists(path);
}

getFullPath = function (path) {
    return FSOObj.GetAbsolutePathName(path);
}
//

//paths
getParent = function(path){
    var splitted=path.split("\\");
    var result="";
    for (var s=0;s<splitted.length-1;s++){
        if (s==0) {
            result=splitted[s];
        } else {
            result=result+"\\"+splitted[s];
        }
    }
    return result;
}


getName = function(path){
    var splitted=path.split("\\");
    return splitted[splitted.length-1];
}
//

function main(){
    if (!ExistsItem(filename)) {
        WScript.Echo(filename + " does not exist");
        WScript.Quit(2);
    }
    var fullFilename=getFullPath(filename);
    var namespace=getParent(fullFilename);
    var name=getName(fullFilename);
    var objFolder=objShell.NameSpace(namespace);
    var objItem=objFolder.ParseName(name);
    //https://msdn.microsoft.com/en-us/library/windows/desktop/bb787870(v=vs.85).aspx
    WScript.Echo(fullFilename + " : ");
    WScript.Echo(objFolder.GetDetailsOf(objItem,-1));

}

main();

Stosowany przeciwko cmd.exe:

C:\Windows\System32\cmd.exe :
File description: Windows Command Processor
Company: Microsoft Corporation
File version: 6.3.9600.16384
Date created: ?22-?Aug-?13 ??13:03
Size: 347 KB
 0
Author: npocmaka,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-01-26 14:08:06