471,347 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Writing a .exe to start a .exe

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
9 2222
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
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
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

<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
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
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
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
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
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.

Similar topics

48 posts views Thread by Joseph | last post: by
10 posts views Thread by Neil Trigger | last post: by
1 post views Thread by Angus Comber | last post: by
10 posts views Thread by Jason Curl | last post: by
2 posts views Thread by melanieab | last post: by
3 posts views Thread by Barry Flynn | last post: by

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.