By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

How to retrieve a handle to the Process by UseShellExecute=true?

P: n/a
Please forgive me re-posting this question since I wasn't clear in my
original post.

----
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. Process.Handle throws an exception of "no process
associated".

It looks to me that if the process is an executable file, getting process
handle is easy. But if the file is a regular file and opened with
ShellExecute, I can't get the process ID.

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 -

Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Fei Yuan" <fe*@carmelvision.com> wrote in message
news:O1*************@TK2MSFTNGP11.phx.gbl...
Please forgive me re-posting this question since I wasn't clear in my
original post.

----
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. Process.Handle throws an exception of "no process
associated".

It looks to me that if the process is an executable file, getting process
handle is easy. But if the file is a regular file and opened with
ShellExecute, I can't get the process ID.

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 -

The handle should be correct, what are you doing with the handle when "no
process associated" is thrown.
It wouild help if you could post some code?.

Willy.
Nov 16 '05 #2

P: n/a
Process p = new Process();
ProcessStartInfo s = new ProcessStartInfo();
s.FileName = @"C:\twain.doc";
p.StartInfo = s;
p.StartInfo.UseShellExecute = true;
p.Start();

The above code will not return a handle or Process when executed, but if you
change "twain.doc" into a "txt" or "exe" file, the handle will be retrieved.
Does it have something to do with the DDE shell execution?

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"Fei Yuan" <fe*@carmelvision.com> wrote in message
news:O1*************@TK2MSFTNGP11.phx.gbl...
Please forgive me re-posting this question since I wasn't clear in my
original post.

----
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. Process.Handle throws an exception of "no process
associated".

It looks to me that if the process is an executable file, getting process
handle is easy. But if the file is a regular file and opened with
ShellExecute, I can't get the process ID.

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 -

The handle should be correct, what are you doing with the handle when "no
process associated" is thrown.
It wouild help if you could post some code?.

Willy.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.