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. Convenience – Executable files can be pinned to the Windows Start Menu and/or Windows 7 Task Bar.
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.
The Script
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.
Links
Download Make EXE from BAT Script from Sysadmin Geek
Download 7-Zip Command Line Tool
Download 7-Zip Advanced 7zSD SFX