Home

ShellExecute

ShellExecute is a Windows API function from the Shell API that performs an operation on a specified file or object, such as opening a document with its associated application, printing, or exploring a folder. It is implemented in shell32.dll and is accessible from C/C++ and other languages via the shellapi.h header.

Signature and variants: HINSTANCE ShellExecute(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd);

Usage notes: ShellExecute can launch a file with its associated program, start a URL or mailto, or

Relation and alternatives: For more control and reliability, developers often prefer ShellExecuteEx or CreateProcess. ShellExecuteEx offers

with
corresponding
Unicode
ShellExecuteW.
If
lpOperation
is
NULL,
the
default
operation
"open"
is
used;
common
values
include
"open",
"print",
or
"explore".
lpFile
specifies
the
target
file
or
URL;
lpParameters
and
lpDirectory
further
customize
the
invocation;
nShowCmd
controls
the
window
display
state.
The
return
value
is
an
HINSTANCE;
a
value
greater
than
32
indicates
success,
while
a
value
in
the
range
of
0–32
indicates
an
error
(e.g.,
file
not
found,
access
denied).
execute
a
program
with
arguments.
It
relies
on
the
system's
file
associations
and
the
user's
environment.
It
does
not
provide
fine-grained
process
control
and
may
present
security
risks
if
used
with
untrusted
input.
explicit
security
attributes,
process
handles,
and
better
error
reporting.
ShellExecute
remains
in
legacy
code
and
is
suitable
for
simple,
one-shot
operations.