Find Application Path from Command Line?

T

Toni

For Windows XP, I'm automating the creation of a task from a .bat file using the AT
command.

Problem is, the application I'm automating could be installed in a different directory
name in C:\Program Files. The program was correctly installed using a setup program.

Can anyone tell me how to find the application path FROM THE COMMAND LINE of an
application?

Thanks!!!
 
J

John John - MVP

Toni said:
For Windows XP, I'm automating the creation of a task from a .bat file using the AT
command.

Problem is, the application I'm automating could be installed in a different directory
name in C:\Program Files. The program was correctly installed using a setup program.

Can anyone tell me how to find the application path FROM THE COMMAND LINE of an
application?

Thanks!!!

dir /s /b "C:\Program Files\program.exe"

Be aware that if you intend to pipe the output it will be devoid of
quotation marks and that the batch file will choke on it.

John
 
T

Toni

dir /s /b "C:\Program Files\program.exe"

Be aware that if you intend to pipe the output it will be devoid of
quotation marks and that the batch file will choke on it.

John

Ah... nice! Thank You!

It's a bit time-consuming... what if I know that the subdirectory begins with an 's'? (I
tried it with a wild-card, didn't work).
 
P

Pegasus [MVP]

Toni said:
...

Ah... nice! Thank You!

It's a bit time-consuming... what if I know that the subdirectory begins
with an 's'? (I tried it with a wild-card, didn't work).

While still using John's command, this particular twist would take twice as
much typing

for /d %a in ("c:\Program Files\s*.*") do dir /s /b "%a\program.exe"
 
T

Toni

While still using John's command, this particular twist would take twice as much
typing

for /d %a in ("c:\Program Files\s*.*") do dir /s /b "%a\program.exe"

Hmmm, well, this lists three subdirs that begin with s and writes "the system cannot
find the file specified".
 
P

Pegasus [MVP]

Toni said:
Hmmm, well, this lists three subdirs that begin with s and writes "the
system cannot find the file specified".

Perhaps the file does not exist in the folder where you're looking . . .
Apply the standard trouble-shooting procedure: If it does not work,
make it visible!

for /d %a in ("c:\Program Files\s*.*") do echo dir /s /b "%a\program.exe"

Note also:
- You *must* run the command from the Command Prompt, not
from the Start/Run box.
- The command is written so that it gets executed from the Command
Line, which is what you asked for. If you put it into a batch file then
you must double the % characters.
 
J

John John - MVP

Pegasus said:
Perhaps the file does not exist in the folder where you're looking . . .
Apply the standard trouble-shooting procedure: If it does not work,
make it visible!

for /d %a in ("c:\Program Files\s*.*") do echo dir /s /b "%a\program.exe"

Note also:
- You *must* run the command from the Command Prompt, not
from the Start/Run box.
- The command is written so that it gets executed from the Command
Line, which is what you asked for. If you put it into a batch file then
you must double the % characters.

I think that he means that the command returns a lot of File Not Found
error verbiage. Example:


C:\>dir /s /b "c:\Program Files\psexec.exe"
c:\Program Files\Sysinternals\PsTools\psexec.exe


one line only returned, where the file actually resides.

as opposed to:

C:\>for /d %a in ("c:\Program Files\s*.*") do dir /s /b "%a\psexec.exe"

C:\>dir /s /b "c:\Program Files\SBApps\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Smart Projects\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Sonic\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Spybot - Search & Destroy\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\stunnel\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Support Tools\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Sysinternals\psexec.exe"
c:\Program Files\Sysinternals\PsTools\psexec.exe

C:\>dir /s /b "c:\Program Files\SystemTools\psexec.exe"
File Not Found



The later 'do echo dir' command that you suggest in your other post
doesn't work because it just recusively echoes the command against all
the s* directories, it doesn't actually find the file and to an
untrained eye it would suggest that the psexec file is in all the \s*
directories:

C:\>for /d %a in ("c:\Program Files\s*.*") do echo dir /s /b "%a\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\SBApps\psexec.exe"
dir /s /b "c:\Program Files\SBApps\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\Smart Projects\psexec.exe"
dir /s /b "c:\Program Files\Smart Projects\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\Sonic\psexec.exe"
dir /s /b "c:\Program Files\Sonic\psexec.exe"

.... and so on.

John
 
J

John John - MVP

John said:
I think that he means that the command returns a lot of File Not Found
error verbiage. Example:


C:\>dir /s /b "c:\Program Files\psexec.exe"
c:\Program Files\Sysinternals\PsTools\psexec.exe


one line only returned, where the file actually resides.

as opposed to:

C:\>for /d %a in ("c:\Program Files\s*.*") do dir /s /b "%a\psexec.exe"

C:\>dir /s /b "c:\Program Files\SBApps\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Smart Projects\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Sonic\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Spybot - Search & Destroy\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\stunnel\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Support Tools\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Sysinternals\psexec.exe"
c:\Program Files\Sysinternals\PsTools\psexec.exe

C:\>dir /s /b "c:\Program Files\SystemTools\psexec.exe"
File Not Found



The later 'do echo dir' command that you suggest in your other post
doesn't work because it just recusively echoes the command against all
the s* directories, it doesn't actually find the file and to an
untrained eye it would suggest that the psexec file is in all the \s*
directories:

C:\>for /d %a in ("c:\Program Files\s*.*") do echo dir /s /b
"%a\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\SBApps\psexec.exe"
dir /s /b "c:\Program Files\SBApps\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\Smart Projects\psexec.exe"
dir /s /b "c:\Program Files\Smart Projects\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\Sonic\psexec.exe"
dir /s /b "c:\Program Files\Sonic\psexec.exe"

... and so on.

Oh crud... I'm slipping! But even with the "echo" removed the second
command still returns the File Not Found error verbiage.

John
 
P

Pegasus [MVP]

John John - MVP said:
I think that he means that the command returns a lot of File Not Found
error verbiage. Example:


C:\>dir /s /b "c:\Program Files\psexec.exe"
c:\Program Files\Sysinternals\PsTools\psexec.exe


one line only returned, where the file actually resides.

as opposed to:

C:\>for /d %a in ("c:\Program Files\s*.*") do dir /s /b "%a\psexec.exe"

C:\>dir /s /b "c:\Program Files\SBApps\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Smart Projects\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Sonic\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Spybot - Search & Destroy\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\stunnel\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Support Tools\psexec.exe"
File Not Found

C:\>dir /s /b "c:\Program Files\Sysinternals\psexec.exe"
c:\Program Files\Sysinternals\PsTools\psexec.exe

C:\>dir /s /b "c:\Program Files\SystemTools\psexec.exe"
File Not Found



The later 'do echo dir' command that you suggest in your other post
doesn't work because it just recusively echoes the command against all the
s* directories, it doesn't actually find the file and to an untrained eye
it would suggest that the psexec file is in all the \s* directories:

C:\>for /d %a in ("c:\Program Files\s*.*") do echo dir /s /b
"%a\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\SBApps\psexec.exe"
dir /s /b "c:\Program Files\SBApps\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\Smart Projects\psexec.exe"
dir /s /b "c:\Program Files\Smart Projects\psexec.exe"

C:\>echo dir /s /b "c:\Program Files\Sonic\psexec.exe"
dir /s /b "c:\Program Files\Sonic\psexec.exe"

... and so on.

John

Well, if this is what the OP wants then he needs to have a proper batch file
like the one below. It suppresses all error messages but returns the full
path to the file that he is after.

[01] @echo off
[02] set ProgName=program.exe
[03]
[04] set Filename=
[05] for /d %%d in ("c:\Program Files\s*.*") do call :Sub %%d
[06] if "%FileName%"=="" (echo File "%ProgName%" not found) else echo File
Name=%Filename%
[07] goto :eof
[08]
[09] :Sub
[10] for /F "delims=" %%f in ('dir /s /b "%*\%ProgName%" 2^>nul') do set
Filename=%%f

Instructions to the OP:
- Adjust Line 02 to suit your environment.
- Unwrap all lines that your newsreader might have wrapped around.
- Remove the line numbers.
- Save the code in c:\Toni.bat
- Run c:\Toni.bat from a Command Prompt.
 
T

Toni

Well, if this is what the OP wants then he needs to have a proper batch file like the
one below. It suppresses all error messages but returns the full path to the file that
he is after.

[01] @echo off
[02] set ProgName=program.exe
[03]
[04] set Filename=
[05] for /d %%d in ("c:\Program Files\s*.*") do call :Sub %%d
[06] if "%FileName%"=="" (echo File "%ProgName%" not found) else echo File
Name=%Filename%
[07] goto :eof
[08]
[09] :Sub
[10] for /F "delims=" %%f in ('dir /s /b "%*\%ProgName%" 2^>nul') do set Filename=%%f

Instructions to the OP:
- Adjust Line 02 to suit your environment.
- Unwrap all lines that your newsreader might have wrapped around.
- Remove the line numbers.
- Save the code in c:\Toni.bat
- Run c:\Toni.bat from a Command Prompt.

AH! This is EXACTLY what I want - with a little mod of adding /a for the dir command so
it looks at all files including hidden & system files.

Thank You to everyone who helped!
 
P

Pegasus [MVP]

Toni said:
Well, if this is what the OP wants then he needs to have a proper batch
file like the one below. It suppresses all error messages but returns the
full path to the file that he is after.

[01] @echo off
[02] set ProgName=program.exe
[03]
[04] set Filename=
[05] for /d %%d in ("c:\Program Files\s*.*") do call :Sub %%d
[06] if "%FileName%"=="" (echo File "%ProgName%" not found) else echo
File Name=%Filename%
[07] goto :eof
[08]
[09] :Sub
[10] for /F "delims=" %%f in ('dir /s /b "%*\%ProgName%" 2^>nul') do set
Filename=%%f

Instructions to the OP:
- Adjust Line 02 to suit your environment.
- Unwrap all lines that your newsreader might have wrapped around.
- Remove the line numbers.
- Save the code in c:\Toni.bat
- Run c:\Toni.bat from a Command Prompt.

AH! This is EXACTLY what I want - with a little mod of adding /a for the
dir command so it looks at all files including hidden & system files.

Thank You to everyone who helped!

Thanks for the feedback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top