473,388 Members | 1,417 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,388 software developers and data experts.

Process.ExitCode fails

I am trying to get the exit code of an application (IE) after the process
closes. On my system I keep getting an exception error. "No process is
associated with the object." The Process class is suppose to keep some
administrative information available on a closed process (i.e., the ExitCode,
HasExited, etc.) but it seems to not do this. Does anyone know how to get
around this problem?

The code is a simple C# form with a button. The button's click code is below.

private void button1_Click(object sender, EventArgs e)
{
Process spawned = Process.Start("iexplore.exe");
Thread.Sleep(2000);
if (spawned.Responding)
{
Thread.Sleep(10000);
spawned.CloseMainWindow();
spawned.Close();
spawned.Refresh();
int exitCode = spawned.ExitCode;
}
}

--
-----------
Thanks,
Steve
Apr 3 '07 #1
2 5501
I found out that the Close() method caused all references to the process to
be gone. I removed it and all worked well.
--
-----------
Thanks,
Steve
"SteveT" wrote:
I am trying to get the exit code of an application (IE) after the process
closes. On my system I keep getting an exception error. "No process is
associated with the object." The Process class is suppose to keep some
administrative information available on a closed process (i.e., the ExitCode,
HasExited, etc.) but it seems to not do this. Does anyone know how to get
around this problem?

The code is a simple C# form with a button. The button's click code is below.

private void button1_Click(object sender, EventArgs e)
{
Process spawned = Process.Start("iexplore.exe");
Thread.Sleep(2000);
if (spawned.Responding)
{
Thread.Sleep(10000);
spawned.CloseMainWindow();
spawned.Close();
spawned.Refresh();
int exitCode = spawned.ExitCode;
}
}

--
-----------
Thanks,
Steve
Apr 3 '07 #2
On Tue, 03 Apr 2007 11:00:03 -0700, SteveT <St****@newsgroups.nospam
wrote:
I am trying to get the exit code of an application (IE) after the process
closes. On my system I keep getting an exception error. "No process is
associated with the object." The Process class is suppose to keep some
administrative information available on a closed process (i.e., the
ExitCode, HasExited, etc.) but it seems to not do this.
Your code explicitly frees all resources associated with the process and
then explicitly tells the Process instance to discard all information it
has cached with the process. I don't find it surprising that you cannot
at that point retrieve the exit code.

IMHO, your code should look more like this:

Process spawned = Process.Start("iexplore.exe");

Thread.Sleep(2000);
if (spawned.Responding)
{
int exitCode;

Thread.Sleep(10000);
spawned.CloseMainWindow();
spawned.WaitForExit();

exitCode = spawned.ExitCode;
}
else
{
spawned.Kill();
}

Note that I also added the else clause to kill the process if you've given
up on it. It's not very nice to start a process and then just leave it
around if you decide it's not doing what you want it to. If your code
sample has left out additional management you're doing to prevent this,
then obviously you can ignore that addition.

Pete
Apr 3 '07 #3

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

Similar topics

0
by: Dan McGuffin | last post by:
I am trying to develop some vb.net code that will will store 1 or more processes in an array of processes, then loop through the array determining when each one has exited. Upon each one exiting, I...
10
by: Tony | last post by:
I am running an application called AcroComm.exe to poll time clocks here at our company. I have written a small C# app that will poll the clocks based on information found in a DB. My problem is...
2
by: Grigs | last post by:
Hello, I am attempting to write a Web Method in my Web Service that starts a process that runs the XCOPY command with passed in parameters. It is failing on me through code. However, if I take...
4
by: Christian Billig | last post by:
Hi, well i've a problem and i don't know how to solve it. I wrote a function, which starts a Process for a user by using the API CreateProcessWithLogon. Afterwards i want to know if the...
11
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very...
4
by: Andy | last post by:
I am calling out to an executable using the System.Diagnostics.Process methods and specifically attempting to trap for errors (at least trying to learn how to trap for errors). I arranged the data...
1
by: tenpsa | last post by:
Hi, I have a C# application that uses the System.Diagnostics.Process functionality to execute other processes (to install a couple of .msi files). Here's my code so far: ...
0
by: Daniel | last post by:
System.Diagnostics.Process.Start fails on windows server 2003 the process returns process.ExitCode == 0 but executing any process with System.Diagnostics.Process.Start on windows xp works fine....
1
by: ranju | last post by:
I am trying to spawn a process (say an exe file) with different user crendentials than that of the current user. 1) Called LogonUserEx() to logon the user and recieve a handle to the token that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.