Detect if application started from zip file

My programs are usually distributed as a zip file containing the exe as well as a folder structure with DLLs, etc. Sometimes new users will download it and try and run the exe from within the zip file.

At present I raise an error about the DLLs not found and call Application.Terminate but it seems to keep running due to MadExcept and they will see more errors if they choose to continue.

Is there a way to detect if the exe is withing a zip file and terminate more cleanly after that first fatal error?

In my experience, running or attempting to open files directly from a zip file happens like this:

  1. the file is unzipped to a temp directory
  2. the file is then run / viewed / processed.

A quick test here on Win 10 shows that running an exe from a zip unzips the exe into a folder with a .zip extension then runs it (ParamStr(0)).

My suggestion would be to check the folder that the app is running in and see if it has a .zip extension, then handle it from there.


1 Like

Thanks Aaron.

I just tried this on W10 and found that Params(0) contained “AppData\Local\Temp” but not anything with “zip”. This is possibly because I have 7Zip installed?

Either way, checking for “AppData\Local\Temp” should cover it no matter what tool Windows uses.

I still have the problem that calling Application.Terminate still lets the user progress further by clicking Continue to the MadExcept prompts.

OK, it looks like calling Halt instead stops MadExcept from offering the option to Continue.

1 Like

Your path check sounds much more reliable.


I would run SameText( ExtractPath(Applilication.ExeName), IncludeTrailingPathDelimiter(GetEnvironmentVariable(‘TEMP’))) is true and if true then terminate the application.

1 Like

Good idea Logan.

Because there’s a random folder added to the temp folder for the unzipping, I ended up with this:

  AppFolder := LowerCase(ExtractFilePath(Application.ExeName));
  TempFolder := LowerCase(IncludeTrailingPathDelimiter(GetEnvironmentVariable('TEMP')));
  if Pos(TempFolder,AppFolder) > 0 then
    ShowMessage('Application needs to be unzipped first. Terminating now.');
    ForcedHalt := True;

The ForcedHalt is used in the finalization section to bypass the unloading of the DLLs that were never loaded due to the error in the initialization.

1 Like


Thanks for posting this.

Is there a reason you prefer zip deployment over installer?

Convenience (for me) at present.