473,465 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
2 8576
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: PattyB | last post by:
Hi, I am using useshellexecute to run a program from VB.NET. When I set UseShellExecute = False I can examine the stdout and stderror, which is great. However, UseShellExecute will choke, if...
1
by: Fei Yuan | last post by:
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...
4
by: jam | last post by:
Dear All, I have a command process running xcopy in console, and now I want to execute the program Rsync After the files are copied...how could i do?? Process p10=new Process();...
6
by: danl | last post by:
I need to be able to execute a .bat file from a C# web application I have the following code that compliles and seems to run fine, but the bat file never does it's work...
15
by: jcrouse | last post by:
Here is my code: Dim sw As StreamWriter = File.CreateText(Application.StartupPath & "\mameversion.bat") sw.WriteLine(lblMameExePath.Text & " -help >""" & Application.StartupPath &...
6
by: jcrouse | last post by:
This is kind of a continuation of another thread that was somewhat resolved: Well, the dilemma seems to be this. I want to be able to hide the DOS box AND pause the code until execution is...
1
by: John Crouse | last post by:
I am using the following code sucessfully on Windows 2000 and Windows XP. However, in WIndows 98 it seems to hang on the WaitForExit. What are my options here? MsgBox("Please be patient. This...
1
by: Robert | last post by:
Hello, I am doing an automatic backup service using c# and VS2003. To achieve this i must call an executable file. So far I have made it all work using Process, code looks like this: ...
4
by: Paul | last post by:
Hi, I am trying to start a process hidden. My code: wordprocess = new System.Diagnostics.Process(); ; wordprocess.StartInfo = new System.Diagnostics.ProcessStartInfo(wcmd, args);...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.