1

Topic: Start of the program and transmission to it of control

I in program . have 2 buttons, one opens a file .pdf, the second launches program . and closes program .. A situation: if in the beginning there was a pushed button of start of a file .pdf after that, pushing of the second button launches program ., but it opens in a background under all programs and after closing of program . control is transferred to other program, instead of ours. The sample of the code of start of the program: void __ fastcall TMainForm:: Button2Click (TObject *Sender) {ShellExecute (NULL, NULL, ".exe", NULL, "", SW_SHOWNORMAL); Close ();} There is a question how correctly to launch the program .exe and to transfer to its control?

2

Re: Start of the program and transmission to it of control

Hello, lsv, you wrote: lsv> There is a question how correctly to launch the program .exe and to transfer to its control? If I correctly understood, it is necessary to launch the program CCC.exe in a background and to transfer control only after end AAA.exe? If both programs with source codes it is necessary to create named  or a semaphore,  it in AAA.exe and to expect in CCC.exe. If CCC.exe the indirect utility the first that comes to mind - to launch CCC.exe in mode SUSPENDED (it is required CreateProcess instead of ShellExecute), then CreateRemoteThread + the first scenario with a mjuteksom/semaphore and call ResumeThread in the implemented code. Only it is necessary to implement at first the code in another's process with the help  and specially created DLL. It is possible even one command and a flow to create and library to load, in a network there are examples (DLL Injection). It is possible and more , without any libraries, by record of the machine code in storage of other process. Instead of  it is possible still WaitForSingleObject to make on HANDLE process which beforehand needs to be received through OpenProcess for AAA.exe

3

Re: Start of the program and transmission to it of control

Hello, lsv, you wrote: lsv> I in program . have 2 buttons, one opens a file .pdf, the second launches program . and closes program .. lsv> the Situation: if in the beginning there was a pushed button of start of a file .pdf after that, pushing of the second button launches program ., but it opens in a background under all programs and after closing of program . control is transferred to other program, instead of ours. lsv> the sample of the code of start of the program: lsv> void __ fastcall TMainForm:: Button2Click (TObject *Sender) lsv> {lsv> ShellExecute (NULL, NULL, ".exe", NULL, "", SW_SHOWNORMAL); lsv> Close (); lsv>} lsv> There is a question how correctly to launch the program .exe and to transfer to its control? And at what here .pdf? Or you too open it through ShellExecute, any Adobe? I would launch . by means of CreateProcess; thus . inherits privileges on SetForegroundWindow.

4

Re: Start of the program and transmission to it of control

Hello, Maniacal, you wrote: M> If I correctly understood, it is necessary to launch the program CCC.exe in a background and to transfer control only after end AAA.exe? Not absolutely in a background, simply one program should launch another, and itself to be closed, i.e. from the point of view of the user, it pushes the button, we admit with a title "to Continue operation in ", at it is launched CCC.exe and it continues to work in it, but sometimes the program CCC.exe is launched somewhere in a background and focus is transferred not to it, and other application. Hello, VladFein, you wrote: VF> And at what here .pdf? Or you too open it through ShellExecute, any Adobe? A Pdf-file here as, it is simple in the program there is a button of discovery of any file, pdf, doc, any, name it "to Read the instruction", and yes it as opens through ShellExecute. The matter is that, as I described above, I need to close the first program and to continue to work in another but if I from program AAA launch any document after that program  opens in a background and control will then be told to any left program that terribly enrages users.

5

Re: Start of the program and transmission to it of control

Hello, lsv, you wrote: lsv> Not absolutely in a background, simply one program should launch another, and itself to be closed, i.e. from the point of view of the user, it pushes the button, we admit with a title "to Continue operation in ", at it is launched CCC.exe and it continues to work in it, but sometimes the program CCC.exe is launched somewhere in a background and focus is transferred not to it, and other application. I.e. a problem what focus is not transferred to the program? In general, the problem is played back if to open the document BBB.pdf, then to launch CCC.exe, in a case if CCC.exe has time to be launched earlier, the document BBB.pdf then opens and focus switches to it. Here at all I do not know what to do, except crutches in the form of that AAA.exe will be simple to close the window and some time to track window focus CCC.exe, doing its by active, if something happens, and then on the sly to complete the operation through N seconds. P.S. With pdf does not roll, Adobe Reader at first opens the window, then returns performance of function ShellExecute and only then starts the document to open. And here with  the document it turns out, since Word at first shows splash-screen and returns control ShellExecute, and after document discovery does the window by active. P.P.S. Tried to set the fourth parameter ShellExecute NULL as it is specified in an example, application hangs to death. Rolls only "".