Which program file is executed?

J

Joe User

I have two related questions. I am using Win XP SP3.


1. How do I know what program (folder and file name) is executed when I
click on shortcut?

For some shortcuts, the answer seems self-evident: right-click on the
shortcut icon, click on Properties, and look at Target in the Shortcut tab.

But for other sortcuts, e.g. Excel, the Shortcut tab does not tell me
anything useful.

I don't know if the shortcuts for Office 2003 (or perhaps all MS) products
are a special case. Even if they are, I am interested in knowing how to
find the real "target" for those shortcuts, too.

I know that I can search for, e.g., excel.exe. But what if I have multiple
files with that name on my system, and/or for some reason I don't trust my
assumptions about which file the shortcut is actually linked to?


2. When I execute a program from the DOS prompt (Start > Run > cmd), how can
I determine the full path (folder and file name) that is executed?

When I execute a program from the Start > Run window, how can I determine
the full path (folder and file name) that is executed?

I am surprised to find that those are not identical. For example, I can
execute `excel` from Program > Run, but not from Start > Run > cmd. Yet I
can execute `telnet` from either. What's up with that? Again, are Office
2003 (or all MS) products simply a special case?

I know that the PATH environment is used, at least for DOS prompt execution.
How do I know the actual path in which the program was found? (Without
trying each path myself.)

Also, if I enter only the basename (e.g. telnet instead of telnet.exe), I
believe that at least two extensions are tried, .exe and .bas. (There might
be others, AFIK.) How do I know the actual file name (extension) that was
used? (Without trying each one myself.)


Basically, I want to know what tools I can use to troubleshoot the
unexpected if/when it arises.
 
J

John Wunderlich

I have two related questions. I am using Win XP SP3.


1. How do I know what program (folder and file name) is executed
when I click on shortcut?

For some shortcuts, the answer seems self-evident: right-click on
the shortcut icon, click on Properties, and look at Target in the
Shortcut tab.

But for other sortcuts, e.g. Excel, the Shortcut tab does not tell
me anything useful.

I don't know if the shortcuts for Office 2003 (or perhaps all MS)
products are a special case. Even if they are, I am interested in
knowing how to find the real "target" for those shortcuts, too.

I know that I can search for, e.g., excel.exe. But what if I have
multiple files with that name on my system, and/or for some reason
I don't trust my assumptions about which file the shortcut is
actually linked to?


2. When I execute a program from the DOS prompt (Start > Run >
cmd), how can I determine the full path (folder and file name)
that is executed?

When I execute a program from the Start > Run window, how can I
determine
the full path (folder and file name) that is executed?

I am surprised to find that those are not identical. For example,
I can execute `excel` from Program > Run, but not from Start > Run
that? Again, are Office 2003 (or all MS) products simply a
special case?

I know that the PATH environment is used, at least for DOS prompt
execution. How do I know the actual path in which the program was
found? (Without trying each path myself.)

Also, if I enter only the basename (e.g. telnet instead of
telnet.exe), I believe that at least two extensions are tried,
.exe and .bas. (There might be others, AFIK.) How do I know the
actual file name (extension) that was used? (Without trying each
one myself.)


Basically, I want to know what tools I can use to troubleshoot the
unexpected if/when it arises.

Assuming that the command in question opens a window, perhaps the
easiest way to determine the exact command and path that was used to
open that program would be to use Microsoft's freeware program
"Process Explorer"

<http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx>

Download it and start it up, then select View->Select Columns and
under the "Process Image" tab, put a checkmark next to "Command
Line". This will cause the entire command line that was used to
start a process/program to be displayed in the window. Once you
start your program -- whatever it is you do to start it -- bring the
Process Explorer window to the foreground and drag the "Bullseye"
symbol at the top of the Process Explorer window to the window of the
process that you want to know the path that launched it. Process
Explorer will then highlight the line corresponding to that program.
Look in the "Command Line" column and you will see the entire
path/file that was used to launch that program.

HTH,
John
 
J

Joe User

John Wunderlich said:
<http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx> [....]
This will cause the entire command line that was used to
start a process/program to be displayed in the window.

Thanks. Sounds like a useful tool to have. I will look into it.

But for my questions, I am looking for an answer that does not require that
I actually the program in question or click on the shortcut.

I have many situations in mind. But certainly one of them is when I am
suspicious about what program is actually executed. I do not want to risk
running the program to find out.

And, no, not all programs open a window. For example, the DOS commands
`nslookup` and `ipconfig`.


----- original message -----
 
P

Pegasus [MVP]

Joe User said:
I have two related questions. I am using Win XP SP3.


1. How do I know what program (folder and file name) is executed when I
click on shortcut?

For some shortcuts, the answer seems self-evident: right-click on the
shortcut icon, click on Properties, and look at Target in the Shortcut
tab.

But for other sortcuts, e.g. Excel, the Shortcut tab does not tell me
anything useful.

I don't know if the shortcuts for Office 2003 (or perhaps all MS) products
are a special case. Even if they are, I am interested in knowing how to
find the real "target" for those shortcuts, too.

I know that I can search for, e.g., excel.exe. But what if I have
multiple files with that name on my system, and/or for some reason I don't
trust my assumptions about which file the shortcut is actually linked to?


2. When I execute a program from the DOS prompt (Start > Run > cmd), how
can I determine the full path (folder and file name) that is executed?

When I execute a program from the Start > Run window, how can I
determine the full path (folder and file name) that is executed?

I am surprised to find that those are not identical. For example, I can
execute `excel` from Program > Run, but not from Start > Run > cmd. Yet I
can execute `telnet` from either. What's up with that? Again, are Office
2003 (or all MS) products simply a special case?

I know that the PATH environment is used, at least for DOS prompt
execution. How do I know the actual path in which the program was found?
(Without trying each path myself.)

Also, if I enter only the basename (e.g. telnet instead of telnet.exe), I
believe that at least two extensions are tried, .exe and .bas. (There
might be others, AFIK.) How do I know the actual file name (extension)
that was used? (Without trying each one myself.)


Basically, I want to know what tools I can use to troubleshoot the
unexpected if/when it arises.

When you type the name of a program at the Command Prompt then the
executable must either reside in the current folder or in one of the folders
listed in the %path% variable (unless it is a program that is internal to
the Command Processor such as "copy").

When you type the program name into the Run box then the executable must
either reside in on of the folders listed in the %path% variable or it must
have a registry key here: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App
Paths\.
 
J

Joe User

Pegasus said:
When you type the name of a program at the Command Prompt [... vs ...]
When you type the program name into the Run box

Aha! Thanks. That explains the difference.

I 'spose there is no native command that searches %path% and
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\ for us, or I
presume you would have mentioned it.

If I wrote a (Excel) VBA macro, are there kernel functions that will resolve
the search for me?

Or are there kernel functions that will return the value of %path% and the
contents of HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\?

Unfortunately, VBA is the only programming language I have available to me
on my computer.


----- original message ------
 
P

Pegasus [MVP]

Joe User said:
Pegasus said:
When you type the name of a program at the Command Prompt [... vs ...]
When you type the program name into the Run box

Aha! Thanks. That explains the difference.

I 'spose there is no native command that searches %path% and
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\ for us, or I
presume you would have mentioned it.

If I wrote a (Excel) VBA macro, are there kernel functions that will
resolve the search for me?

Or are there kernel functions that will return the value of %path% and the
contents of HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\?

Unfortunately, VBA is the only programming language I have available to me
on my computer.

Your fortune is about to turn. Since Windows 98, all Windows machines have
VB Script implemented. This language is ideally suited for this type of
thing. Save the code below as c:\windows\which.vbs, then run it like so:

cscript //nologo which excel

It will scan all %path% folders and also the registry location I gave you.
Enjoy!

'==================================================
'Find out the location of the nominated executable.
' Version: 2.0
' 21.3.2009 FNL
'==================================================
Set oWshShell = WScript.CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oArgs = WScript.Arguments

If oArgs.count <> 1 Then
WScript.Echo "Usage: which.vbs NameOfExecutable"
WScript.Quit
End If

SearchFolders
SearchRegistry
WScript.Echo("File not found")

Sub SearchFolders
aAux = Split(oArgs(0), ".") 'Split the parameter into sName & extension
sName = aAux(0)
sExt = LCase(oWshShell.ExpandEnvironmentStrings("%PathExt%"))
If UBound(aAux) > 0 Then sExt = "." & aAux(1) 'Extension is in parameter
aExtensions = Split(sExt, ";")

aPaths = Split(oWshShell.CurrentDirectory & ";" _
& oWshShell.ExpandEnvironmentStrings("%path%"), ";")

For p = 0 To UBound(aPaths)
if right(aPaths(p), 1) <> "\" then aPaths(p) = aPaths(p) & "\"
For e = 0 To UBound(aExtensions)
If oFSO.FileExists(aPaths(p) & sName & aExtensions(e)) Then
WScript.Echo "Path entry:", aPaths(p) & sName & aExtensions(e)
WScript.Quit
End If
Next
Next
End Sub

Sub SearchRegistry
HKLM=&H80000002
sKeyPath1 = "Software\Microsoft\Windows\CurrentVersion\App Paths\"
sKeyPath2 = "HKLM\" & sKeyPath1

Set oWshShell = WScript.CreateObject("WScript.Shell")
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")

oReg.EnumKey HKLM, sKeyPath1, aSubkeys
If InStr(oArgs(0), ".") = 0 _
Then sName = LCase(oArgs(0)) & ".exe" _
Else sName = LCase(oArgs(0))

For Each sSubkey In aSubkeys
If sName = LCase(sSubkey) Then
WScript.echo "Registry entry: ", oWshShell.RegRead(sKeyPath2 & sSubkey
& "\")
WScript.Quit
End If
Next
End Sub
 
J

Joe User

Pegasus said:
Save the code below as c:\windows\which.vbs [....]
It will scan all %path% folders and also the registry
location I gave you.

Fantastic! Thanks much.

That disposes of Question #2. Any insight into Question #1, to wit....

1. How do I know what program (folder and file name) is executed when I
click on shortcut?

For some shortcuts, the answer seems self-evident: right-click on the
shortcut icon, click on Properties, and look at Target in the Shortcut tab.

But for other sortcuts, e.g. Excel, the Shortcut tab does not tell me
anything useful.

I don't know if the shortcuts for Office 2003 (or perhaps all MS) products
are a special case. Even if they are, I am interested in knowing how to
find the real "target" for those shortcuts, too.

I know that I can search for, e.g., excel.exe. But what if I have multiple
files with that name on my system, and/or for some reason I don't trust my
assumptions about which file the shortcut is actually linked to?

Again, this is for Win XP SP3.


----- original message -----

Pegasus said:
Joe User said:
Pegasus said:
When you type the name of a program at the Command Prompt [... vs ...]
When you type the program name into the Run box

Aha! Thanks. That explains the difference.

I 'spose there is no native command that searches %path% and
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\ for us, or I
presume you would have mentioned it.

If I wrote a (Excel) VBA macro, are there kernel functions that will
resolve the search for me?

Or are there kernel functions that will return the value of %path% and
the contents of HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppPaths\?

Unfortunately, VBA is the only programming language I have available to
me on my computer.

Your fortune is about to turn. Since Windows 98, all Windows machines have
VB Script implemented. This language is ideally suited for this type of
thing. Save the code below as c:\windows\which.vbs, then run it like so:

cscript //nologo which excel

It will scan all %path% folders and also the registry location I gave you.
Enjoy!

'==================================================
'Find out the location of the nominated executable.
' Version: 2.0
' 21.3.2009 FNL
'==================================================
Set oWshShell = WScript.CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oArgs = WScript.Arguments

If oArgs.count <> 1 Then
WScript.Echo "Usage: which.vbs NameOfExecutable"
WScript.Quit
End If

SearchFolders
SearchRegistry
WScript.Echo("File not found")

Sub SearchFolders
aAux = Split(oArgs(0), ".") 'Split the parameter into sName & extension
sName = aAux(0)
sExt = LCase(oWshShell.ExpandEnvironmentStrings("%PathExt%"))
If UBound(aAux) > 0 Then sExt = "." & aAux(1) 'Extension is in parameter
aExtensions = Split(sExt, ";")

aPaths = Split(oWshShell.CurrentDirectory & ";" _
& oWshShell.ExpandEnvironmentStrings("%path%"), ";")

For p = 0 To UBound(aPaths)
if right(aPaths(p), 1) <> "\" then aPaths(p) = aPaths(p) & "\"
For e = 0 To UBound(aExtensions)
If oFSO.FileExists(aPaths(p) & sName & aExtensions(e)) Then
WScript.Echo "Path entry:", aPaths(p) & sName & aExtensions(e)
WScript.Quit
End If
Next
Next
End Sub

Sub SearchRegistry
HKLM=&H80000002
sKeyPath1 = "Software\Microsoft\Windows\CurrentVersion\App Paths\"
sKeyPath2 = "HKLM\" & sKeyPath1

Set oWshShell = WScript.CreateObject("WScript.Shell")
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")

oReg.EnumKey HKLM, sKeyPath1, aSubkeys
If InStr(oArgs(0), ".") = 0 _
Then sName = LCase(oArgs(0)) & ".exe" _
Else sName = LCase(oArgs(0))

For Each sSubkey In aSubkeys
If sName = LCase(sSubkey) Then
WScript.echo "Registry entry: ", oWshShell.RegRead(sKeyPath2 &
sSubkey & "\")
WScript.Quit
End If
Next
End Sub
 
P

Pegasus [MVP]

I believe that shortcuts with unidentifiable paths are created under the
"namespace" concept. I have never looked into this concept but here is a
link that might get you started:
http://www.codeproject.com/shell/namespcextguide1.asp. Note also that each
shortcut contains a lot of invisible binary information that will point you
to the application, probably via some registry key.

Joe User said:
Pegasus said:
Save the code below as c:\windows\which.vbs [....]
It will scan all %path% folders and also the registry
location I gave you.

Fantastic! Thanks much.

That disposes of Question #2. Any insight into Question #1, to wit....

1. How do I know what program (folder and file name) is executed when I
click on shortcut?

For some shortcuts, the answer seems self-evident: right-click on the
shortcut icon, click on Properties, and look at Target in the Shortcut
tab.

But for other sortcuts, e.g. Excel, the Shortcut tab does not tell me
anything useful.

I don't know if the shortcuts for Office 2003 (or perhaps all MS) products
are a special case. Even if they are, I am interested in knowing how to
find the real "target" for those shortcuts, too.

I know that I can search for, e.g., excel.exe. But what if I have
multiple
files with that name on my system, and/or for some reason I don't trust my
assumptions about which file the shortcut is actually linked to?

Again, this is for Win XP SP3.
 
J

Joe User

Pegasus said:

Thanks for the pointer. Interesting reading.



----- original message -----

Pegasus said:
I believe that shortcuts with unidentifiable paths are created under the
"namespace" concept. I have never looked into this concept but here is a
link that might get you started:
http://www.codeproject.com/shell/namespcextguide1.asp. Note also that each
shortcut contains a lot of invisible binary information that will point you
to the application, probably via some registry key.

Joe User said:
Pegasus said:
Save the code below as c:\windows\which.vbs [....]
It will scan all %path% folders and also the registry
location I gave you.

Fantastic! Thanks much.

That disposes of Question #2. Any insight into Question #1, to wit....

1. How do I know what program (folder and file name) is executed when I
click on shortcut?

For some shortcuts, the answer seems self-evident: right-click on the
shortcut icon, click on Properties, and look at Target in the Shortcut
tab.

But for other sortcuts, e.g. Excel, the Shortcut tab does not tell me
anything useful.

I don't know if the shortcuts for Office 2003 (or perhaps all MS)
products
are a special case. Even if they are, I am interested in knowing how to
find the real "target" for those shortcuts, too.

I know that I can search for, e.g., excel.exe. But what if I have
multiple
files with that name on my system, and/or for some reason I don't trust
my
assumptions about which file the shortcut is actually linked to?

Again, this is for Win XP SP3.
 
E

Etal

Joe said:
1. How do I know what program (folder and file name) is
executed when I click on shortcut?

For some shortcuts, the answer seems self-evident:
right-click on the shortcut icon, click on Properties, and
look at Target in the Shortcut tab.

But for other sortcuts, e.g. Excel, the Shortcut tab does not
tell me anything useful.

I don't know if the shortcuts for Office 2003 (or perhaps all
MS) products are a special case. Even if they are, I am
interested in knowing how to find the real "target" for those
shortcuts, too.

I know that I can search for, e.g., excel.exe. But what if I
have multiple files with that name on my system, and/or for
some reason I don't trust my assumptions about which file the
shortcut is actually linked to?

<sarcasm>
Why keep shortcut-targets transparent to the users?
That's a stupid notion.
</sarcasm>

msKB #243630 - How 'Windows Installer' Shortcuts Work
<http://support.microsoft.com/kb/814841/>

Remedy: 'GetMSIShortcutTarget' by Ramesh Srinivasan
<http://www.winhelponline.com/blog/>

Thanks Ramesh.
 
B

Bobbi

I remember a long time ago when I first got Office 2003 that the desktop
shortcuts were weird in several respects, that being one of them. Another
was that I couldn't drag and drop a file onto the shortcut and have it open
the document. I replaced them all by finding the location of the executable
file for each Office Application and creating a new shortcut. For Excel, the
executable file is "EXCEL.EXE", for Word it's "WINWORD.EXE", for Publisher
it's "MSPUB.EXE".

You may have to use the Windows Search feature to find the location of the
files in question. You can right click on each file name and choose "Create
shortcut". Windows will tell you it can't create a shortcut in the search
box and ask if you want to create it on the desktop. You can say yes, and
then you'll have better shortcuts with better information.

Bobbi
 

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