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?
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.