473,406 Members | 2,387 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,406 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 2314
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
10
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
1
by: Angus Comber | last post by:
Hello I am writing a real time program which queues up a number of tasks for processing. Each item in the queue must be submitted to a device sequentially. ie it is not possible to just blast...
10
by: Jason Curl | last post by:
Dear C group, I'm very interested in writing portable C, but I only have GNU, Sparc and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers to...
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
4
by: Gidi | last post by:
Hi, i have a byte array, and i'm writing it to a file, i want to start a new line, how can i do it? (like WriteLine in StreamWriter) I'm using FileStream: FileStream fs = new...
3
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
6
by: mcse jung | last post by:
Here is asample program that writes a program and then executes it. Do you knowof a much simpler way of writing a program that writes a program? """...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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.