RSS

How-To Geek

When you get down to it, batch files and executable files work pretty much the same way. Both are simply a set of instructions and logic for Windows execute. So why would you want to convert a batch file to an executable if they essentially work the same? Here are a few reasons:

Portability – you can include additional tools in your EXE file that the batch file depends on.

Protection – an EXE provides protection for your source script to ensure it is not inadvertently modified.

With the script below, you can easily build your own executable file from a batch file, complete with and required embedded tools.

Configuration

This script takes advantage of a 7-Zip advanced SFX (SelF eXtractor) to bundle and execute the batch file with any included tools. So you will need to download (links provided at the end)these and extract them to a single directory.

Once you have everything downloaded, set the ‘PathTo7Zip’ variable in the script to the location where these files where downloaded.

Conclusion

It is important to note that while the resulting file runs exactly the same as the source BAT file, this is not a true batch to executable conversion. The resulting file is an EXE, however it is intended to be used for self-extracting installers. When you execute the resulting EXE file, the process goes something like this:

The contents of the EXE file are extracted to the temp directory.

The config file generated by the script is read.

The batch file contained in the EXE file is executed in a new command window.

Once finished, the temp files are removed.

On Windows Vista and new OS’s, you may see the following message box after the script is run. After selecting ‘This program installed correctly’, the message box will not be displayed in the future for this file.

Because the EXE file launches in a new window, the typical way of logging output (using the ‘>’ char) will not work as expected. In order to log the output, you would need to handle this natively in your source script.

Despite these minor inconveniences, being able to convert a batch file to an executable can really come in handy.

GEEK TRIVIA

DID YOU KNOW?

Scientists have calculated that the theoretical maximum height a tree could obtain (before the energy demands of pushing water ever higher against the force of gravity outweighed the energy the tree could expend) is 426 feet tall; currently the tallest tree in the world is a 379.3 foot tall Redwood tree.