Differences between CreateProcess and ShellExecute

What are the main differences between the two? I am ready to run only another EXE from my (C ++) application. Are there differences when inheriting environments, security features, etc.

+6
source share
3 answers

The main difference between CreateProcess and ShellExecute is this: CreateProcess more low-oriented and ShellExec on the leverage of the high user who sees the user in Explorer.

For example, using CreateProcess , you can use a command line that is longer than MAX_PATH . It has a limit of 32,768 characters. You can also use CreateProcess to run the program (if you have sufficient permissions) on another Windows desktop, for example, on the login screen.

Another example. You can use ShellExecute to launch the Control Panel or open any program that existed on the computer for editing, for example, JPG. Thus, you are working with ShellExecute next to the corresponding actions in Windows Explorer.

+11
source

The main difference is flexibility. ShellExecute easier to use but not very flexible. CreateProcess is a pain to use, but allows you to do something.

For example, using CreateProcess you can specify descriptors (pipes or files) that will be used for standard input / output / error flows in a child element. ShellExecute does not give you the desired way to do this.

Perhaps it’s also worth noting that although ShellExecute can be used to directly run the executable file, its main purpose is to “execute” document files — for example, say “execute” to “what.html” and it launches your default web browser and loads the specified HTML file into it. You can do this with CreateProcess , but for this you (usually) start by calling FindExecutable to find the program associated with the given data file, and then execute by passing the data file as a parameter.

+4
source

CreateProcess returns the handle and identifier of the initial process, and the main thread in the PROCESS_INFORMATION structure

+2
source

Source: https://habr.com/ru/post/916615/


All Articles