Windows:用于读取可执行文件版本信息的命令行? [英] Windows: Command line to read version info of an executable file?
问题描述
Windows是否有可以在命令外壳程序中运行的可执行文件,该外壳程序返回可执行文件(.exe)的版本号?
Does Windows have an executable that I can run in the command shell which returns the version number of an executable (.exe) file?
我看到很多问题,这些问题说明了如何使用不同的语言来实现它,并引用了编写它的第三方软件,但是我找不到简单的shell命令来实现它.其他要点,如果我不需要安装任何东西.
I see a lot of questions that show how to do it from different languages, and references to third party software to write it, but I can't find a simple shell command to do it. Additional points if I don't need to install anything.
它必须以普通用户身份运行.不是管理员.
It must be run as normal user. Not administrator.
推荐答案
wmic datafile where name="C:\\Windows\\System32\\msiexec.exe" get Version /value
您可以使用wmic
进行操作.您可以将其包装到批处理文件中
You can use wmic
to do it. And you can wrap it into a batch file
@echo off
setlocal enableextensions
set "file=%~1"
if not defined file goto :eof
if not exist "%file%" goto :eof
set "vers="
FOR /F "tokens=2 delims==" %%a in ('
wmic datafile where name^="%file:\=\\%" get Version /value
') do set "vers=%%a"
echo(%file% = %vers%
endlocal
将其另存为(示例)getVersion.cmd
,然后调用为getVersion.cmd "c:\windows\system32\msiexec.exe"
Save it as (example) getVersion.cmd
and call as getVersion.cmd "c:\windows\system32\msiexec.exe"
已编辑以适应评论,并且不需要管理员权限.在这种情况下,将使用混合的cmd/javascript文件查询wmi.用法相同
edited to adapt to comments and not require administrator rights. In this case, an hybrid cmd/javascript file is used to query wmi. Same usage
@if (@this==@isBatch) @then
@echo off
setlocal enableextensions
set "file=%~f1"
if not exist "%file%" goto :eof
cscript //nologo //e:jscript "%~f0" /file:"%file%"
endlocal
exit /b
@end
var file = WScript.Arguments.Named.Item('file').replace(/\\/g,'\\\\');
var wmi = GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2')
var files = new Enumerator(wmi.ExecQuery('Select Version from CIM_datafile where name=\''+file+'\''))
while (!files.atEnd()){
WScript.StdOut.WriteLine(files.item().Version);
files.moveNext();
};
WScript.Quit(0)
这篇关于Windows:用于读取可执行文件版本信息的命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!