BatExe
======

BatExe creates executables out of batch files.

BatExe 1.1.0 is copyright 2009, 2024 D. Bohdan and is distributed under the MIT No Attribution License (MIT-0), which is like the MIT License but doesn't require credit. See `license.txt`.

You can find BatExe on SourceForge at <https://sourceforge.net/projects/batexe/>.

1 Description
-------------

BatExe is a program that lets you to package arbitrary files plus a batch-file script in an x86 Microsoft Windows executable. Possible uses include creating portable applications, packaging installers, making self-extracting archives, and distributing single-binary Python programs. When run, the executable will extract all of your files to a temporary directory (the exact location is determined by the user's `TEMP` environment variable) and execute the batch file.

2 Directory structure
---------------------

    batexe
    |-- 7z
    |   |-- 7za.exe
    |   `-- license.txt
    |-- build.bat
    |-- license.txt
    |-- project
    |   |-- data.txt
    |   `-- run.bat
    |-- readme.txt
    |-- sfx
    |   |-- sfx.exe
    |   `-- sfx.nsi
    |-- test.bat
    `-- vendor
        |-- ExecDos
        |   |- ...
        |   ...
        `-- Nsis7z
            |- ...
            ...

3 Usage
-------

1. Extract the archive with BatExe. This will create the directory `batexe`.
2. Place the batch file you want packaged in the `batexe\project` directory along with other files you wish to include. You can name the batch file either `run.bat` or `runh.bat`. This will determine the way it will run: `run.bat` runs in a visible command-line window, while `runh.bat` is hidden from the user. (Note: you can have both, but if you do, only `runh.bat` will run.)
3. Start `build.bat` and wait until the build completes. (The build process consists of compressing the `project` directory into a 7-Zip archive and appending it to the binary stub `sfx/sfx.exe`). The generated executable will be named `project.exe`.

4 How the executable works
--------------------------

When you start a BatExe-generated executable, it extracts the data inside to a temporary directory and runs the included batch file (either `runh.bat` or `run.bat`). The script runs with the working directory set to the executable's current location. The path to the temporary directory (the directory with the batch file and any other packaged files) is passed to the script as its first command-line argument. (On Windows XP it will look like `C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\nsl18F.tmp` for the user `Administrator`). If the user decides to pass arguments to the executable, the arguments will come after this argument.

The executable waits for the batch file to finish, removes the temporary directory, and terminates.

5 Known bugs and issues
-----------------------

There are currently no known bugs.

BatExe executables cause false positives with anti-malware. Your antivirus will quite probably detect executables built with BatExe as malware.

6 Compatibility
---------------

This version of BatExe has been tested on Windows XP (32-bit) and Windows 10 (64-bit).

7 Acknowledgments
-----------------

BatExe includes an unmodified official binary of the command-line version of 7-Zip from <https://7-zip.org/a/7za920.zip>. 7-Zip is free software distributed under the GNU LGPL 2.1+ license; see `7z\license.txt`. To obtain the source code, go to <http://www.7-zip.org/>.

The binary stub is built with NSIS. It uses the plug-ins Nsis7z (GNU LGPL v2.1+ like 7-Zip) and ExecDos (zlib license). Their source code is included with BatExe.

8 Building `sfx.exe`
--------------------

To compile the BatExe binary, you will need the following:

* NSIS 3 - <http://nsis.sourceforge.io/>
* Nsis7z plug-in - <http://nsis.sourceforge.io/Nsis7z_plug-in>. Included with BatExe in `vendor\Nsis7z`. Use the `x86-unicode` version.
* ExecDos plug-in - <http://nsis.sourceforge.io/ExecDos_plug-in>. Included with BatExe in `vendor\ExecDos`. Use the `x86-unicode` version.
* Resource Hacker 3.6.0 – Optional. Needed to remove the generic NSIS installer icon from the final executable, which is misleading when the project isn't an installer. Download from <https://web.archive.org/web/20150324102917/https://www.angusj.com/resourcehacker/>.

Instructions:

1. Install NSIS.
2. Copy the plug-ins to the NSIS plug-in directory. (`C:\Program Files (x86)\NSIS\Plugins\x86-unicode` by default on a 64-bit system.)
3. Optionally, copy `ResHacker.exe` to the directory `batexe\sfx`.
4. Compile `batexe\sfx\sfx.nsis` with MakeNSIS. Right-click the file and select "Compile NSIS Script" if you installed NSIS with the default settings.
