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

Writing a .exe to start a .exe

P: n/a
Ok....Super newbie here in C#...

I am trying to write an application (myapp.exe) that will start an
application called abc.exe and if it is terminated, will restart it.
(or rerun myapp.exe) I have tried it in several scripting languages,
but they tend to use ntvdm.exe and peg the processor.

Sounds easy, I know...but I am not real "sharp" at this. (horrible pun
fully intended)

Dec 9 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
look at process start
http://msdn.microsoft.com/library/de...starttopic.asp

and also look at how to montor running processes:

http://www.developersdex.com/gurus/code/244.asp

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

<ri******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Ok....Super newbie here in C#...

I am trying to write an application (myapp.exe) that will start an
application called abc.exe and if it is terminated, will restart it.
(or rerun myapp.exe) I have tried it in several scripting languages,
but they tend to use ntvdm.exe and peg the processor.

Sounds easy, I know...but I am not real "sharp" at this. (horrible pun
fully intended)

Dec 9 '05 #2

P: n/a
The following seems like it should work... you might want to add some exit
conditions; as long as the app loads OK, it just reloads it every time it
exits. It doesn't thrash the CPU or anything.

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = new
System.Diagnostics.ProcessStartInfo("notepad.exe") ;
while(proc.Start()) {
proc.WaitForExit();
}

That do?

Marc

<ri******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Ok....Super newbie here in C#...

I am trying to write an application (myapp.exe) that will start an
application called abc.exe and if it is terminated, will restart it.
(or rerun myapp.exe) I have tried it in several scripting languages,
but they tend to use ntvdm.exe and peg the processor.

Sounds easy, I know...but I am not real "sharp" at this. (horrible pun
fully intended)

Dec 9 '05 #3

P: n/a
1. Start the abc.exe using the System.Diagnostic.Process
class
2. Set process' EnableRaisingEvents to *true*
3. Hook to Exited event in order to be notified when the process terminates.

Read carefully the docs regarding EnableRaisingEvents property and Exited
even. There is some important information such as that you cannot use
reference to terminated process to restart it.
--
HTH
Stoitcho Goutsev (100) [C# MVP]

<ri******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Ok....Super newbie here in C#...

I am trying to write an application (myapp.exe) that will start an
application called abc.exe and if it is terminated, will restart it.
(or rerun myapp.exe) I have tried it in several scripting languages,
but they tend to use ntvdm.exe and peg the processor.

Sounds easy, I know...but I am not real "sharp" at this. (horrible pun
fully intended)

Dec 9 '05 #4

P: n/a

<ri******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Ok....Super newbie here in C#...

I am trying to write an application (myapp.exe) that will start an
application called abc.exe and if it is terminated, will restart it.
(or rerun myapp.exe) I have tried it in several scripting languages,
but they tend to use ntvdm.exe and peg the processor.

Sounds easy, I know...but I am not real "sharp" at this. (horrible pun
fully intended)


And what kind of application is abc.exe, are you sure it's a 32 bit
application? My guess is that it's a 16bit application that runs in the
ntvdm. This scenario is not supported though.

Willy.

Dec 9 '05 #5

P: n/a
Thank you everyone for all the timely help. I am struggling through a
bit of this and have actually gotten the application (abc.exe) to
launch from myapp.exe. Now I just have to figure out how to loop this
so that if abc.exe is terminated for some reason, that it will restart.
(any thoughts on that would be greatly appreciated)

To answer the question, abc.exe is a 32 bit java app. that runs in its
own process. The problem comes in that when one of our other java apps
is shut down, it takes out the abc.exe process.

Thanks again everyone for all the help.
Willy Denoyette [MVP] wrote:
<ri******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Ok....Super newbie here in C#...

I am trying to write an application (myapp.exe) that will start an
application called abc.exe and if it is terminated, will restart it.
(or rerun myapp.exe) I have tried it in several scripting languages,
but they tend to use ntvdm.exe and peg the processor.

Sounds easy, I know...but I am not real "sharp" at this. (horrible pun
fully intended)


And what kind of application is abc.exe, are you sure it's a 32 bit
application? My guess is that it's a 16bit application that runs in the
ntvdm. This scenario is not supported though.

Willy.


Dec 9 '05 #6

P: n/a
Hi richwood,

There were couple of solutions in the post.
Don't any of them work for you?
--

Stoitcho Goutsev (100) [C# MVP]

<ri******@gmail.com> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com...
Thank you everyone for all the timely help. I am struggling through a
bit of this and have actually gotten the application (abc.exe) to
launch from myapp.exe. Now I just have to figure out how to loop this
so that if abc.exe is terminated for some reason, that it will restart.
(any thoughts on that would be greatly appreciated)

To answer the question, abc.exe is a 32 bit java app. that runs in its
own process. The problem comes in that when one of our other java apps
is shut down, it takes out the abc.exe process.

Thanks again everyone for all the help.
Willy Denoyette [MVP] wrote:
<ri******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
> Ok....Super newbie here in C#...
>
> I am trying to write an application (myapp.exe) that will start an
> application called abc.exe and if it is terminated, will restart it.
> (or rerun myapp.exe) I have tried it in several scripting languages,
> but they tend to use ntvdm.exe and peg the processor.
>
> Sounds easy, I know...but I am not real "sharp" at this. (horrible pun
> fully intended)
>


And what kind of application is abc.exe, are you sure it's a 32 bit
application? My guess is that it's a 16bit application that runs in the
ntvdm. This scenario is not supported though.

Willy.

Dec 9 '05 #7

P: n/a
Actually, yes....They did help quite a bit. I am to the point where I
can open abc.exe in its own process, but I trying to figure out how to
put a "Wait" in, so that when the process terminates, it will start up
again.

Dec 9 '05 #8

P: n/a
RCS
Check out the WaitForExit method in the Process class.. You can either wait
indefinitely - or wait a specific amount of time..

Then you'd obviously just put that inside a loop: start the app, wait to
exit, rinse and repeat

HTH

<ri******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Actually, yes....They did help quite a bit. I am to the point where I
can open abc.exe in its own process, but I trying to figure out how to
put a "Wait" in, so that when the process terminates, it will start up
again.

Dec 9 '05 #9

P: n/a
To start a process you use the Process class. You can also attach to already
running process:

while(true)
{
using(Process p = new Process(...))
{
p.Start()
p.WaitForExit()
}

}

When you start the process your method will block until the started process
exits. The you loop and start it again. You may also set some condition to
make the loop end.

If you don't want to block the main process you can use what I suggested

p = new Process(...)
p.EnableRaiseEvents = true;
p.Exited = new EventHandler(ProcessExited);
p.Start()

void ProcessExited(object sender, EventHandler e)
{
((Process)p).Dispose();
Process p = new Process(...)
p.EnableRaiseEvents = true;
p.Exited = new EventHandler(ProcessExited);
p.Start()

}
--

Stoitcho Goutsev (100) [C# MVP]

<ri******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Actually, yes....They did help quite a bit. I am to the point where I
can open abc.exe in its own process, but I trying to figure out how to
put a "Wait" in, so that when the process terminates, it will start up
again.

Dec 9 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.