检测程序是否已安装以及使用cmd.exe的位置

时间:2014-02-01 22:00:49

标签: windows batch-file powershell cmd

Windows有程序start.exe,以某种方式知道如何通过他们的名字打开程序,如“firefox”

在cmd.exe中键入start firefox会打开firefox,假设已安装。 是否有类似的命令启动它将返回文件路径而不是启动应用程序?

也适用于任何类似但正确的解决方案

更新: 其他答案建议使用where命令,这适用于系统目录中的ping等程序,但找不到start之类的firefox。

1 个答案:

答案 0 :(得分:6)

看看这个注册表项。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

在其中你会发现类似于firefox的内容。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe]
@="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"
"Path"="C:\\Program Files (x86)\\Mozilla Firefox"

这里有一点从Powershell读取值。使用reg.exe可以从批处理文件中完成同样的事情。

$Firepath = get-item -path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe'
$Firepath.GetValue('')