如何在批处理脚本中找到应用程序的完整路径 [英] How do I find full path to an application in a batch script
问题描述
如何在批处理脚本中找到应用程序XYZ的完整路径(如果已安装)
How do I in a batch script find the full path to application XYZ if it is installed
说明:
- 该应用程序不在PATH中
- 在这种情况下,我所拥有的只是它的名字"ISTool.exe",我想得到 C:\ Program \ ISTool \ ISTool.exe
推荐答案
我从其他人那里得到的答案有效(但是速度较慢或使用了多余的文件)并且适用于任何exe,但并不真正适合我的需求.
The answers I got from others worked (but slow or used extra files) and worked for any exe but didn't really suit my needs.
因为我想找到一个特定的exe,所以我使用注册查询.我找到了一个包含要查找的数据的密钥,并将其提取出来.
Since I wanted to find a particular exe I went looking in the registry using REG QUERY instead. I found a key that contained the data I wanted to find and extracted that.
结果很快,只有几行代码,但不是很漂亮,也不可重用.
The result is fast, has few lines of code but is not very pretty nor reusable.
简短示例:
@ECHO off
SETLOCAL
set found=
FOR /F "tokens=1-3 delims= " %%a IN ('REG QUERY "HKEY_CLASSES_ROOT\Applications\ISTool.exe\shell\OpenWithISTool\command"') DO (
set found=%%c
)
for /f "tokens=1-2" %%a in ("%found%") do (
set my_exe=%%a
)
echo %my_exe%
ENDLOCAL
这将导致"C:\Program\ISTool\ISTool.exe"
(带引号)
注意:上面的delims =后跟一个制表符
This results in "C:\Program\ISTool\ISTool.exe"
(with quotes)
Note: delims= above is followed by a tab-char
这篇关于如何在批处理脚本中找到应用程序的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!