How to retrieve a handle to the Process from ShellExecute()?

F

Fei Yuan

Starting an external process needs to pass it a ProcessStartInfo() object.
ProcessStartInfo has a property "UseShellExecute" that can open/print a
file. However, I'm having a hard time getting the handle to the application
after calling Process.Start(). Basically, I need the handle to monitor the
application launched.

Anybody knows where I can retrieve this handle or process ID? I also looked
into Windows API's "shell32.dll" "Execute()" function, it however returns a
handle that's only good to check if any error occurred, not the actual
Process handle.

Any help or hint will be appreciated!

Regards,
- Fei -
 
P

Paul E Collins

Fei Yuan said:
I'm having a hard time getting the handle to the
application after calling Process.Start().

Is this what you want?

Process p = new Process( ... );
IntPtr h = p.Handle;

P.
 
F

Fei Yuan

No, accessing that field will throw an exception "No associated process".
The key is that the process is not started directly, but through the Shell,
with Shell commands.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top