问题描述
有没有办法从命令行检测安装在 Windows 机器上的无法比较的版本?
我尝试使用 wmic 但它似乎不起作用
wmic product where "name like 'Beyond%%'"
No Instance(s) Available.
解决方法
Beyond Compare 版本可以在注册表中找到:
超越对比 4:
version: '3.8'
services:
test-app:
build:
context: .
dockerfile: Dockerfile
container_name: test-app-container
volumes:
- ./app/:/var/www/html/
environment:
PGID: 1000
PUID: 1000
ports:
- "8080:80"
超越对比 3:
HKCU\SOFTWARE\Scooter Software\Beyond Compare 4\Version
HKLM\SOFTWARE\Scooter Software\Beyond Compare 4\Version
HKLM\SOFTWARE\Scooter Software\Beyond Compare\Version
超越对比 2:
HKCU\SOFTWARE\Scooter Software\Beyond Compare 3\Version
,
我刚刚下载并使用批处理文件进行了测试。
我有 Windows 10(32 位),所以我的文件夹安装位于:
%ProgramFiles%\Beyond Compare 4\BCompare.exe
。
所以如果它不在那里,你应该在这个脚本上改变它!
只需将此代码复制并粘贴到记事本中并将其另存为: Get_File_Version.bat
@echo off & color 0B
Title Get Version of any application using WMIC
Set "AppPath=%ProgramFiles%\Beyond Compare 4\BCompare.exe"
echo( & echo( Getting Version of "%AppPath%"
Call :GetVersion "%AppPath%" Version
cls
echo( & echo( %AppPath% : v%Version%
Pause
Exit
::----------------------------------------------------------------------------------------
:GetVersion <App> <Version>
Rem The argument %~1 represent the full path of the application without the double quotes
Rem The argument %2 represent the variable to be set (in our case %2=Version)
Set "App=%~1"
Set "App=%App:\=\\%"
FOR /F "tokens=2 delims==" %%I IN (
'wmic datafile where "name='%App%%'" get version /Value 2^>^nul'
) DO FOR /F "delims=" %%A IN ("%%I") DO SET "%2=%%A"
Exit /b
::----------------------------------------------------------------------------------------
编辑: 根据@Chris Kennedy 的回答,我想查询注册表以提取可执行路径及其版本。
@echo off & color 0B
Title Get ExePath and Version From Registry using Reg Query
@for /f "tokens=3* skip=2 delims= " %%a in (
'Reg Query "HKCU\SOFTWARE\Scooter Software\Beyond Compare" /v ExePath'
) do (
set "ExePath=%%a%%b"
)
@for /f "tokens=3 skip=2 delims= " %%a in (
'Reg Query "HKCU\SOFTWARE\Scooter Software\Beyond Compare" /v Version'
) do (
set "Version=%%a"
)
echo( ExePath = "%ExePath%"
echo( Version = v%Version%
Pause & Exit