473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Create Process and Wait

I am using CreateProcessWithLogonW to run an external application, the
problem I am having is that the C# program does not wait until the external
program finishes running before continuing. The external program is a
console application and it does not interact with users, how can I make my
C# program wait until the program initiated by CreateProcessWithLogonW API
completes running before continuing?

here's my API code.

bool ret = CreateProcessWithLogonW(_logonName, _domain,
_password,
LOGON_WITH_PROFILE, null, sb,
NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT,
IntPtr.Zero, "c:\\",
ref startInfo, out processInfo);
Peter

--
Thanks
-------------------
cz****@wsinc.com
Nov 15 '05 #1
4 17047
Peter wrote:

I am using CreateProcessWithLogonW to run an external application, the
problem I am having is that the C# program does not wait until the external
program finishes running before continuing. The external program is a
console application and it does not interact with users, how can I make my
C# program wait until the program initiated by CreateProcessWithLogonW API
completes running before continuing?

here's my API code.

bool ret = CreateProcessWithLogonW(_logonName, _domain,
_password,
LOGON_WITH_PROFILE, null, sb,
NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT,
IntPtr.Zero, "c:\\",
ref startInfo, out processInfo);

Peter

--
Thanks
-------------------
cz****@wsinc.com


Whatever the equivalent for WaitForSingleObject is in .Net.

You call WFSO on the processInfo process handle. When that becomes signaled,
the process has terminated.
Nov 15 '05 #2

Hi Peter,

Thank you for posting in the community!

Based on my understanding, you use CreateProcessWithLogonW to create a new
process through P/invoke. You want to be notified when that new process
exits.

======================================
Because the new created process has almost no relationship with your
process, there is not an easy way to access the information of the new
created process.
Interprocess access in Win32 need much support of the operating system.

And in .Net, there is no way to get what you want, because .Net does not
expose function for interprocess operation. If you can I suggest you use
.Net Process class to replace CreateProcessWithLogonW API.
For Process class, it expose an Exited event, which you can be notified
when you created process exited.

If you still can not use Process class, the only workaround I can think of
is kept enumerating all the processes in the system to query if the new
created process exited.

This is not a good solution, and it has a poor performance.

For How to enumerate process in Win32, please refer to:
http://support.microsoft.com/default...b;en-us;175030

=====================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
You need to wait on the process handle. This handle becomes signalled when
the process exits. You can PInvoke to WaitForSingleObject, passing in
processInfo.hProcess as the handle to wait on. Or you can subclass the
System.Threading.WaitHandle class and assign processInfo.hProcesss to its
Handle property - then use the normal WaitOne method.

Also, remember to close processInfo.hProcess and processInfo.hThread when
you no longer need them (calling Dispose or Close on a WaitHnadle subclass
will also do this).

"Peter" <cz****@wsinc.com> wrote in message
news:eo*************@TK2MSFTNGP11.phx.gbl...
I am using CreateProcessWithLogonW to run an external application, the
problem I am having is that the C# program does not wait until the external program finishes running before continuing. The external program is a
console application and it does not interact with users, how can I make my
C# program wait until the program initiated by CreateProcessWithLogonW API
completes running before continuing?

here's my API code.

bool ret = CreateProcessWithLogonW(_logonName, _domain,
_password,
LOGON_WITH_PROFILE, null, sb,
NORMAL_PRIORITY_CLASS | CREATE_UNICODE_ENVIRONMENT,
IntPtr.Zero, "c:\\",
ref startInfo, out processInfo);
Peter

--
Thanks
-------------------
cz****@wsinc.com

Nov 15 '05 #4
Hi Stephen,

Oh, I think my original reply has some error. Yes, we can P/invoke
WaitForSingleObject to get this done.

Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
1
by: Markus Franz | last post by:
Hi. I created a little script: for currenturl in sys.argv: pid = os.fork() if pid == 0: signal.alarm(10) do_something() # placeholder for the download and print routine
2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
6
by: benz | last post by:
I am trying to fork and exec a child by python. Additionally, I am attempting to have a spinning slash while the child is running. My code is as below: import sys, os, time def...
4
by: colson | last post by:
I know how to create a new process using System.Diagnostics.Process and wait for the process to end using WaitForExit(). How do I wait for multiple processes? Is there an equivalent to...
8
by: mandydhaliwal | last post by:
Hi all, I am porting a win32 c++ program on Linux which first reads a list of processes and their paths from a file.Then this program should launch all of thesese processes. I tried to...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
13
by: Edwin Smith | last post by:
I have a form which displays a DataGridView table generated with the VS2005 tools. The database is a Pervasive v.9 with an ODBC driver. The DataGridView works great except when I'm done and I...
1
by: jazon | last post by:
Let me start by saying this for an Operating Systems class. No, I don't expect the work to be done for me. The assignment is as follows: To be honest, I feel like a fish out of water, like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.