如何在windows中使用命令提示符获取chrome版本

jjhzyzn0  于 2022-11-18  发布在  Windows
关注(0)|答案(6)|浏览(317)

是否有可能在windows中使用命令提示符获得版本安装chrome版本?
试过了,

"C:\Program Files\Google\Chrome\Application\chrome.exe" -version
 "C:\Program Files\Google\Chrome\Application\chrome.exe" --version
 "C:\Program Files\Google\Chrome\Application\chrome.exe" -product-version
 "C:\Program Files\Google\Chrome\Application\chrome.exe" --product-version

当我这样做的时候,一个浏览器示例正在打开。我应该使用什么标志来获取版本。
我使用的是Windows 7。谷歌浏览器版本是67.0.3396.87。
先谢了

5ssjco0h

5ssjco0h1#

到今天为止,user4851仍然在工作。我看了一下他链接的bug报告,建议的解决方案不再对我起作用了。
我的目录中有一个新的hkey,它允许你查询chrome版本,而不知道实际的安装位置:

reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version
tyg4sfes

tyg4sfes2#

有一个关于这个的bug:https://bugs.chromium.org/p/chromium/issues/detail?id=158372

原始答案(但请参阅下面的更新)

对我有效的是

wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get Version /value

打印

Version=67.0.3396.99

被一些空行包围。
bug注解中还有一些其他的建议,比如查询注册表。

更新

Chromium团队的某个人在bug注解线程中发布了这个“完全不支持”的批处理文件:

@ECHO OFF

:: Look for machine-wide Chrome installs (stable, Beta, and Dev).
:: Get the name, running version (if an update is pending relaunch), and
:: installed version of each.
FOR %%A IN (
    {8A69D345-D564-463c-AFF1-A69D9E530F96},
    {8237E44A-0054-442C-B6B6-EA0509993955},
    {401C381F-E0DE-4B85-8BD8-3F3F14FBDA57}) DO (
  reg query HKLM\Software\Google\Update\Clients\%%A /v name /reg:32 2> NUL
  reg query HKLM\Software\Google\Update\Clients\%%A /v opv /reg:32 2> NUL
  reg query HKLM\Software\Google\Update\Clients\%%A /v pv /reg:32 2> NUL
)

:: Look for Chrome installs in the current user's %LOCALAPPDATA% directory
:: (stable, Beta, Dev, and canary).
:: Get the name, running version (if an update is pending relaunch), and
:: installed version of each.
FOR %%A IN (
    {8A69D345-D564-463c-AFF1-A69D9E530F96},
    {8237E44A-0054-442C-B6B6-EA0509993955},
    {401C381F-E0DE-4B85-8BD8-3F3F14FBDA57},
    {4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}) DO (
  reg query HKCU\Software\Google\Update\Clients\%%A /v name /reg:32 2> NUL
  reg query HKCU\Software\Google\Update\Clients\%%A /v opv /reg:32 2> NUL
  reg query HKCU\Software\Google\Update\Clients\%%A /v pv /reg:32 2> NUL
)

这可能应该被视为目前的正确道路。

b4wnujal

b4wnujal3#

我尝试了Kilian的答案,但是在我的例子中,我是通过一个服务对一组机器远程运行它,所以我不认为HKEY_CURRENT_USER是有效的:

ERROR: The system was unable to find the specified registry key or value.

假设您知道exe的位置,您可以尝试不同的方法,读取exe档案的version属性:

# Powershell
# Older versions install to the 32-bit directory
(Get-Item "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe").VersionInfo

# Newer versions use the 64-bit directory
(Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo

ProductVersion   FileVersion      FileName
--------------   -----------      --------
76.0.3809.100    76.0.3809.100    C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

要在cmd.exe中或通过任何子进程调用(python、go os/exec等)使用它,您可以:

powershell -command "&{(Get-Item 'Absolute\path\to\chrome.exe').VersionInfo.ProductVersion}"
5tmbdcev

5tmbdcev4#

仅使用命令行实用程序

dir /B/AD "C:\Program Files (x86)\Google\Chrome\Application\"|findstr /R /C:"^[0-9].*\..*[0-9]$"
78.0.3904.97

仅列出Chrome应用程序文件夹中的目录/AD,缩写形式为/B
findstr /R /C:"..."将以下正则表达式应用于目录列表。该正则表达式匹配以数字^[0-9]开始并以数字[0-9]$结束的每个文件夹名称。在第一个数字和最后一个数字之间允许任何字符.*,但至少应出现一个点\.

e0uiprwp

e0uiprwp5#

user1425134's solution对我很有效,但如果允许你假设Chrome是%PATH%的一部分(如果你可以打开命令提示符,键入chrome启动浏览器),那么它就可以大大简化。
在Powershell中,您可以键入(Get-Command "chrome").Version.ToString()
或者在cmd.exe中,您可以键入powershell -c "(Get-Command "chrome").Version.ToString()"
(same对于Chromium,只需替换命令名称)

j2datikz

j2datikz6#

我可以使用the rust kitty's solution而不需要在路径上使用chrome,如下所示:

  • 从PowerShell:
(Get-Command C:\Program Files (x86)\Google\Chrome\Application\chrome.exe').Version.ToString()
  • 来自cmd:
powershell -command "(Get-Command C:\Program Files (x86)\Google\Chrome\Application\chrome.exe').Version.ToString()"

相关问题