Microsoft KB Archive/243378

{|
 * width="100%"|

PRB: ShellExecuteEx on a Shortcut Does Not Return hProcess

 * }

Q243378

-

The information in this article applies to:


 * Microsoft Win32 Application Programming Interface (API), included with:
 * Microsoft Windows 95
 * Microsoft Windows 98
 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0
 * the operating system: Microsoft Windows 2000

-

SYMPTOMS
When ShellExecuteEx is used to launch a shortcut to a program (for example, a .lnk file), the SHELLEXECUTEINFO.hProcess doesn't get initialized with the handle to the process created by ShellExecuteEx.

CAUSE
ShellExecuteEx obtains an IContextMenu interface associated with the .lnk file and then calls IContextMenu::InvokeCommand to start the shortcut. The CMINVOKECOMMANDINFO or CMINVOKECOMMANDINFOEX structures do not contain a HPROCESS member to return through ShellExecuteEx.

RESOLUTION
The target can be resolved from the shortcut by using the IShellLink interface. The target, which is a file path or an ITEMIDLIST pointer, can then be passed to ShellExecuteEx to obtain the handle to the process that is started.

NOTE: Resolving the shortcut prior to calling ShellExecuteEx still may not return a valid process handle. This can occur if the application being started is already running and a second instance of the application is not allowed, or if a document is being opened through a DDE connection.

STATUS
This behavior is by design.

MORE INFORMATION
Refer to the Platform SDK documentation on the IShellLink interface.

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

"Q179904 HOWTO: Change the Icon of a Shortcut Through IShellLink"