::::: Usage:getPathOfProgram.bat Program
::::: Result:output Pathofprogram
@echo off
Setlocal enabledelayedexpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If havenot the first parameter,output the Usage and exit with the ExitCode 1
If [%1] equ [] (
Call:showhelp%0
Exit/b 1
)
If [%1] equ [/?] (
Call:showhelp%0
Exit/b 1
)
Set Pathofallprogram=%temp%\pathofallprogram
: \\\flush Cache file
If [%1] equ [/f] (
if exist!pathofallprogram! (
Del!pathofallprogram! && Echo Flush Cache successfully
) Else (
echo No cache file,donnot need to flush.
)
Exit/b 0
)
:: Get Program.exe
Set Pro=%1.exe
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: Find gived program's path from Reg,find reg Path:regpath=hklm\software\microsoft\windows\currentversion\app paths\
Set Regpath=hklm\software\microsoft\windows\currentversion\app paths\
:: Set random file to store outputfile
Set tempfile=%temp%\%time::=_%
:: Find gived program path from Reg
Reg query "%regpath%%pro%" 2>nul | find/i "%pro%" >>%tempfile%
If%errorlevel% equ 0 (
for/f "Skip=1 tokens=1,2*"%%a in (%tempfile%) do set pathofprogram=%%c
Echo!pathofprogram!
Del%tempfile%
Exit/b 0
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Find gived program's path from all disk
::%temp%\pathofallprogram Store all EXE file of this computer
:: If havenot this file,it means havenot collect all EXE files in this computer,then excute underside code to collect all E Xcute files,else Find gived EXE file in%temp%\pathofallprogram
:: Collect EXE files in each drive
If not exist!pathofallprogram! (
for/f "tokens=* skip=1"%%a in (' Wmic logicaldisk Where ' drivetype=3 ' Get Name ') do (
Call:listfiles%%a
)
)
for/f "skip=2 tokens=*"%%a in (' find/i ' \%1.exe '!pathofallprogram! ') do (
If [%%a] neq [] Set pathofprogram=%%a
Echo!pathofprogram!
Exit/b 0
)
Goto:eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: Listfiles
::: Give this label a parameter:drive\
::: for example:call:listFiles \ c \
::: The label would collect all EXE files in gived Drive,and store all files to%temp%\pathofallprogram
If [%1] neq [] (
FOR/R%1\%%a in (*.exe) do echo%%a >>!pathofallprogram!
)
Goto:eof
: ShowHelp
Echo Gets the full path to the specified running program
Echo.
Echo Usage:
Echo%1 Program
Echo%1/f refreshes the cache file and finds all executables again
Echo.
Goto:eof
This article is from the "can't remember the former Cup of Wine" blog, please be sure to keep this source http://9429042.blog.51cto.com/9419042/1795123
Get the executable program (. exe) full path