Windows是否具有可以在命令外壳程序中运行的可执行文件,该外壳程序返回可执行文件(.exe)的版本号?
我看到很多问题,这些问题说明了如何使用不同的语言来实现它,并引用了第三方软件来编写它,但是我找不到一个简单的shell命令来实现它。其他要点,如果我不需要安装任何东西。
它必须以普通用户身份运行。不是管理员。
wmic datafile where name="C:\\Windows\\System32\\msiexec.exe" get Version /value
您可以wmic
用来做。您可以将其包装到批处理文件中
@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"
编辑以适应注释并且不需要管理员权限。在这种情况下,将使用混合的cmd / javascript文件查询wmi。用法相同
@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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句