Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store exe in application and extract to specified folder? 2

Status
Not open for further replies.

doctorjellybean

Programmer
May 5, 2003
145
I would like to store an external application (small) inside my compiled program, and when it is needed, extract it to a specified folder, execute it from there and then delete itself when completed.

Executing and deleting it is the easy part, it is storing it within the compiled application which looks like black magic to me. From what I've Googled, it has to be created as a resource file and compiled?

It seems like everybody got their own way of doing things. Maybe someone can explain a painless way of doing it [smile] ?

Thanks.
 
Is not quite as simple. Let me explain:

The file I'm executing is a ghost application. The executed ghost application executes 2 other command line applications, using cmd.exe. When cmd.exe has terminated, then I need a showmessage dialog. Basically I call e.g. test.exe, which in turn invokes cmd.exe to run the applications inside test.exe. ExecAndWait only deals with the original executed file, in this case test.exe. The process I need to establish if it has ended will always be cmd.exe
 
I'm not sure I understand. If the "ghost app" just runs the other two apps, then why not just call the other two apps from the original program?

You should be able to monitor the CMD.EXE process just fine, I would think. What is the issue that you are encountering? Coding a wait cycle after the CreateProcess call, or something else?

----------
Measurement is not management.
 
I'm not sure I understand. If the "ghost app" just runs the other two apps, then why not just call the other two apps from the original program?

Because the other 2 apps are used in tandem with parameters. This is the code in the original batch file
Code:
for %%a in ("*.avs") do wavi.exe "%%a" - | aften.exe -v 0 -b 384 -readtoeof 1 - "Normalized-%%~na_1.5.ac3"
Rather that reinventing the wheel, I just converted the batch file to the ghost app, and my app calls the ghost app.

Now I need a method to monitor the CMD.EXE process, so that a showmessage can appear when CMD.EXE has terminated.

It is a bit long winded I know, but it is easier for me that way lol.
 
FWIW, an example of what they're talking about, this is what I've been using these days, at least until I discover the next bug or piece of missing necessary functionality:

Code:
function execute_program(ExecuteFile, paramstring: string; var ProcID: DWord;
               wait: boolean): DWord;
  var
    StartInfo  : TStartupInfo;
    ProcInfo   : TProcessInformation;
    CreateOK   : Boolean;
    ErrorCode  : DWord;
    AppDone    : DWord;

  begin
    ErrorCode := 0;
    FillChar(StartInfo,SizeOf(TStartupInfo),#0);
    FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
    StartInfo.cb := SizeOf(TStartupInfo);

    CreateOK := Windows.CreateProcess(nil,
                PChar(ExecuteFile + ' ' + paramstring),
                nil, nil, False,
                CREATE_NEW_PROCESS_GROUP+IDLE_PRIORITY_CLASS+SYNCHRONIZE,
                nil, nil, StartInfo, ProcInfo);
    WaitForInputIdle(ProcInfo.hProcess, INFINITE);
    if CreateOK then
      if wait then
        begin
          repeat
            AppDone := WaitForSingleObject(ProcInfo.hProcess, 50);
            ProcessMessage;
          until AppDone <> WAIT_TIMEOUT;
          CloseHandle(ProcInfo.hProcess);
          CloseHandle(ProcInfo.hThread);
        end
      else
        procid := ProcInfo.hProcess;
    GetExitCodeProcess(ProcInfo.hProcess, ErrorCode);
    Execute_Program := ErrorCode;
  end;

Using the command-interpreter like what's been talked about (CMD /C) involves calling the command-line interpreter which in turn runs the command passed it. So ProcInfo.hProcess is the process handle of CMD.EXE - so you should be fine.

----------
Measurement is not management.
 
Thanks Glenn (I think lol). I'll give it a go.

The code in the batch file which I mentioned, is the last line of the batch process. Rather than creating a separate process for each command, I just converted the whole batch file to an exe.
 
A real simple solution is to use "START /Wait MyApp.exe" in your batch file.

Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top