473,625 Members | 2,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process.ExitCod e 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(o bject sender, EventArgs e)
{
Process spawned = Process.Start(" iexplore.exe");
Thread.Sleep(20 00);
if (spawned.Respon ding)
{
Thread.Sleep(10 000);
spawned.CloseMa inWindow();
spawned.Close() ;
spawned.Refresh ();
int exitCode = spawned.ExitCod e;
}
}

--
-----------
Thanks,
Steve
Apr 3 '07 #1
2 5529
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(o bject sender, EventArgs e)
{
Process spawned = Process.Start(" iexplore.exe");
Thread.Sleep(20 00);
if (spawned.Respon ding)
{
Thread.Sleep(10 000);
spawned.CloseMa inWindow();
spawned.Close() ;
spawned.Refresh ();
int exitCode = spawned.ExitCod e;
}
}

--
-----------
Thanks,
Steve
Apr 3 '07 #2
On Tue, 03 Apr 2007 11:00:03 -0700, SteveT <St****@newsgro ups.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(20 00);
if (spawned.Respon ding)
{
int exitCode;

Thread.Sleep(10 000);
spawned.CloseMa inWindow();
spawned.WaitFor Exit();

exitCode = spawned.ExitCod e;
}
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
594
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 want to display the corresponding process' exitcode. I had the following code working a week ago, but then I made some (mostly) cosmetic changes, and now I can't get it to work. Imports System Imports System.Collections Imports...
10
15906
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 that AcroComm will sometimes stop polling in the middle of the process and terminate. The programing manual for the app says that it sends a code to the operating system when it is done that tells what has happend like the following: 0 ...
2
2196
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 the exact same string it is passing and past it into a Command prompt, it works perfectly. That told me it may be a permissions/impersonation issue. I am now running it as a special ServiceAccount I have created that is a Domain Admin. It...
4
3994
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 process already ended and with what exitcode it has finished.
11
3742
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 simple batch file (echo hello world) and was trying to retrieve the standard output but every time I run the code it returns ExitCode as 1.
4
32756
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 to specifically error when calling this executable. System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "intupld.exe"; process.StartInfo.Arguments = hupFile; process.StartInfo.WorkingDirectory =...
1
5500
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: System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.Arguments = sArgs; proc.StartInfo.FileName = "msiexec.exe"; proc.StartInfo.WorkingDirectory = sPath; proc.Start();
0
1796
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. anything to do different for windows server 2003? some special permission for the process that executes another executable with System.Diagnostics.Process.Start ?? here is the code:
1
7459
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 represents the logged-on user. 2) Called ImpersonateLoggedOnUSer() to let the calling thread impersonate the security context of logged on user. 3) Used CreateEnvironmentBlock() to get lpEnv
0
8182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8494
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7178
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4085
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.