Get the executable program (. exe) full path

Source: Internet
Author: User

::::: 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.