How do I find full path to an application in a batch script

前端 未结 6 795
礼貌的吻别
礼貌的吻别 2021-02-19 00:25

How do I in a batch script find the full path to application XYZ if it is installed

Clarifications:

  1. The application is not in the PATH
  2. All I h
6条回答
  •  自闭症患者
    2021-02-19 01:06

    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.

    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.

    Short example:

    @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
    

    This results in "C:\Program\ISTool\ISTool.exe" (with quotes)
    Note: delims= above is followed by a tab-char

提交回复
热议问题