How to determine if a Windows batch file is running from a ZIP archive

One of the ways to distribute our application (on Windows) is a ZIP archive. Inside this archive is a batch file used to run the application. The user must unzip the archive before launching our application, but often users ignore our instructions and try to run the application without unpacking the archive first. When users do this, the application does not start, but it is not obvious (to the user) exactly what caused the crash. We would like to detect from the batch file whether it will be launched from the ZIP archive, and if so, show the user a message reminding him to unpack the archive first.

However, it is not entirely clear to me how to detect this condition. While the package variable %cmdcmdline%contains the command that ran the batch file, there seems to be no way to use the path to reliably determine if the path points to a ZIP archive. For example, I placed the following batch file named test.bat in a ZIP archive:

echo% cmdcmdline%
pause

The output executed from the archive was:

cmd / c "" C: \ Users \ liana \ AppData \ Local \ Temp \ Temp1_test.zip \ test.bat ""

Now it seems likely that Temp1_test.zip is a ZIP archive and not a real directory, but there is no guarantee that it exists. Obviously, Windows knows how to tell the difference, so there must be some more reliable way than just checking if the ".zip" path appears somewhere. But how?

+3
6

"" . ( , ) .

, , , , , , , .

+7

, ?

if not exist "%~dp0\someotherfile" goto print_please_unzip_ffs_message

% ~ dp0 - bat ( , bat )

+4

? , , Windows , . , , .

+1

zip-. SFX . ( ( ) SFX ZIP, SFX .zip, , ).

+1

Windows (explorer.exe) .zip . - .zip, . zip- - , .

Windows, , ZIP-. , , .zip.

, , - .msi, .

0

If you create a batch file named "setup.bat", Windows will unzip all the files in the zip file to the temp directory, instead of prompting the user if they want to.

In setup.bat, you can start with cd /d %~dp0to go to the current executable directory. Then you can just run your program as usual or do some installation.

0
source

Source: https://habr.com/ru/post/1721633/


All Articles