使用PowerShell检查Firefox版本

3
尝试使用PowerShell批处理脚本卸载Firefox。但是我需要知道当前运行的Firefox版本以及“Program Files”下的文件夹名称!我有很多长脚本,例如:https://p0w3rsh3ll.wordpress.com/2012/02/19/get-firefoxinfo/,但我只想要简单的东西,它可以返回当前的Firefox版本。

获取WMI对象 - 类Win32_Product将是检查已安装内容的命令。 - hysh_00
2
请勿使用 Get-WmiObject -Class Win32_Product。它会触发系统上安装的每个软件包的重新配置。参考链接 - Jan Chrbolka
4个回答

3

Firefox特别包含一个命令行选项来获取版本号,并提供了在Windows上如何使用它的说明。这个一行代码将获取您当前的Firefox版本(假设您在正确的文件夹中或者您的Firefox在系统路径中):

$ffversion = [string](.\firefox.exe -v| Write-Output)

| Write-Output 这个命令非常重要,因为存在一个已记录的 bug。然后将结果转换为字符串(也是必要的),并在此保存为变量。


请问您能否提供相应的Bugzilla bug链接,以便我们投票支持修复它? - AxD

1
假设Firefox安装在典型位置:
wmic datafile where name='c:\\program files (x86)\\Mozilla Firefox\\Firefox.exe' get version

1

在PowerShell中尝试以下命令 -

PS> gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString |ogv

enter image description here

这将显示一个弹出窗口,其中包含安装软件的所有版本详细信息。在那里添加条件并将DisplayName设置为Firefox。

您将获得版本号。

在x64机器上,如果您想要使用gp进行操作,则需要

PS> gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString |ogv

谢谢!


0
$firefox = (Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe').'(Default)').VersionInfo

2
请不要仅仅发布代码作为答案,还要提供代码的解释以及它是如何解决问题的。带有解释的答案通常更有帮助和更高质量,并且更有可能吸引赞同。 - Ran Marciano

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接