Anup
Anup

Reputation: 61

Run a Exe from another exe

I want to execute one exe from another exe. but the other exe can not run if first exe is running.

So i want to run the exe and exit from the application before the second exe gets executed.

Any help on this.

Upvotes: 0

Views: 7799

Answers (3)

David Heffernan
David Heffernan

Reputation: 613013

You are going to need a process to sit in the middle if you are not allowed to have the two main processes executing simultaneously. Which means that you need three processes in total. The two main processes, A and C, and the broker in the middle, B. Here's how it goes down:

  • Process A executes.
  • Process A starts process B passing in its process handle.
  • Process A terminates.
  • Process B waits on process handle for process A. That becomes signaled when process A has terminated.
  • Process B starts process C.
  • Process B terminates.

I'm assuming that you already know how to create processes, pass arguments to process, duplicate handles, wait on handles and so on.

Upvotes: 1

AbdulRahman AlHamali
AbdulRahman AlHamali

Reputation: 1941

I am not sure exactly how it is done in Windows, but I think that the general guidelines are the same between linux and windows:

You need to fork a child process, in Linux this is done using fork() function, in Windows I think you can use CreateProcess(). In this child process, you need to call one of the exec functions which changes the code of this child process to the code of any executable that you can specify as a parameter to the exec function.

The code, thus, should be something like this pseudo-code:

c= CreateProcess()
if (c == child)
{
    exec("My other executable.exe")
}

This is the general procedure, but you need to figure out the syntax

Upvotes: 1

Logicrat
Logicrat

Reputation: 4468

Consider a third application, which you launch from your first app. The third one checks to be sure the first one has terminated, then launches the second app and terminates itself. I have had to do this in the past; it works fine.

Upvotes: 2

Related Questions