Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the big deal with ProcessStartInfo.UseShellExecute?

How will ProcessStartInfo.UseShellExecute affect my running process?

Do i need special permissions from UAC to UseShellExecute?

Will it run on diffrent user?

Will it give me new permissions?

like image 209
Danpe Avatar asked Sep 26 '12 13:09

Danpe


1 Answers

Windows has two distinct api functions to get a process started. The low-level one is CreateProcess(), it directly maps to a native api function. And there's ShellExecuteEx(), a function that's implemented by the shell (Explorer). It has a much higher level of abstraction.

They are very different capabilities and that's something you see back in the documentation for ProcessStartInfo. CreateProcess() can only start executable files but it has good support to control a console mode program, including the ability to redirect I/O and control the appearance of the console window. ShellExecuteEx() takes advantage of the capabilities added by the shell, file associations being the big one, so you can start the executable that's registered for a specific filename extension.

Both api functions have options to affect the way the process execute. You'll see a close correlation between the properties of the ProcessStartInfo class and the Process Creation Flags supported by CreateProcess and the fields in the SHELLEXECUTEINFO structure that ShellExecuteEx() uses. But these features don't overlap so that's why you need to tinker with UseShellExecute.

like image 200
Hans Passant Avatar answered Oct 06 '22 01:10

Hans Passant