Antonino Perricone
Antonino Perricone

Reputation: 13

where ShellExecute found the exe files

I am writing a program in pure C, using win32 api.

I need to know the full path of a registered program.

For example if I write

ShellExecute(0,0,"chrome",0,0,SW_SHOW)

the chrome browser starts. How can I obtain "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" from "chrome" as ShellExecute does?

Upvotes: 1

Views: 1833

Answers (2)

Leandro
Leandro

Reputation: 96

The function SHEvaluateSystemCommandTemplate does exactly that. It performs the exact same search algorithm that is performed by ShellExecute. You just pass "chrome.exe" (or even just "chrome"), and the full path to the chrome executable is returned in the ppszApplication parameter.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613412

In this case Chrome has registered itself in the App Paths registry section. More details over on MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121.aspx

Finding an Application Executable

When the ShellExecuteEx function is called with the name of an executable file in its lpFile parameter, there are several places where the function looks for the file. We recommend registering your application in the App Paths registry subkey. Doing so avoids the need for applications to modify the system PATH environment variable.

The file is sought in the following locations:

  • The current working directory.
  • The Windows directory only (no subdirectories are searched).
  • The Windows\System32 directory.
  • Directories listed in the PATH environment variable.
  • Recommended: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

The documentation tells you how the shell searches, and you can replicate that search.

Upvotes: 6

Related Questions