ShellExecute 在哪里找到 exe 文件

where ShellExecute found the exe files

我正在用纯 C 编写程序,使用 win32 api。

我需要知道注册程序的完整路径。

例如如果我写

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

chrome 浏览器启动。我怎样才能像 ShellExecute 那样从 "chrome" 获得 "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

在这种情况下,Chrome 已在“应用程序路径”注册表部分注册了自己。有关 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

documentation 告诉您 shell 是如何搜索的,您可以复制该搜索。