Batch File to Executable
OK. I have to admit it. I got caught in a bit of a fib on Sunday. Actually, it was more of a case of bad proofreading than anything else. In my post Automatic Drive Mapping, I stated:
you can’t make a batch file into an executable
Well, wary DCoT reader D Steele caught me in my mistake and let me know that there are actually several ways that you can convert a batch file into an executable.
I had actually realized this when I was writing the previous post but promptly forgot about it before I submitted the post. So, apologies for the error.
In fact, it is really easy to do. Here is how I do it in AutoIt:
;Make batch executable #include <File.au3> Dim $TempBatchFile = _TempFile(@TempDir,"",".bat") Dim $HideConsole = False FileInstall("MyBatch.bat",$TempBatchFile) If $HideConsole Then RunWait($TempBatchFile,@TempDir,@SW_HIDE) Else RunWait($TempBatchFile,@TempDir) EndIf FileDelete($TempBatchFile) MsgBox(64,"Done","Execution complete!")
Download this code: MyBatch.au3
A couple of little things about this script. It will not show the “DOS box” as it is written. If you want to see the console screen, simply change this line:
Dim $HideConsole = False
to:
Dim $HideConsole = True
The console should now appear.
Also, the line:
FileInstall(“MyBatch.bat”,$TempBatchFile)
is where you put in the full path and name of your batch file. Simply change MyBatch.bat to the name of your batch file. You cannot use a variable for this because of how AutoIt is designed.
Once you have all of these things set, all you need to do is compile your script and you are done! Instantly compiled batch file!
If you found this post useful, why don't you buy me a cup of coffee to show your gratitude?
12 Responses to “Batch File to Executable”
-
Penguin Geek Says:
March 19th, 2007 at 11:02 amI wouldn’t really call that a batch file to executable conversion. I still kinda new to Autoit. But from what I can see, that’s a wrapper program that runs a batch file for you. But it gets the job done! Great tip.
-
Tim Fehlman Says:
March 19th, 2007 at 11:10 amPenguin Geek,
Technically, you are correct. A true batch converter would be significantly more complex and, to be honest, beyond my programming skills.When I look at converting batch files to executables, I typically do it for two reasons:
1. I don’t want someone changing the code
2. I don’t want someone getting the codeThis wrapper performs these two functions and it will keep it safe from the majority of end users. But, if it were to get into the hands of some truly computer savvy individual, it would not take them very long to find the batch file, see the code, change the code, and recompile it.
Tim
-
Crashed Pips Says:
March 19th, 2007 at 2:37 pmConverting batch files to .EXEs…
I commonly use batch and script files in Windows and Linux respectively - they’re easy to code, save time for the end user and work instantly on a single double-click (well, most of the time). Sometimes however, it’s useful to convert them …
-
Jonathan Rothwell Says:
March 19th, 2007 at 2:50 pmI might be stating the obvious here Tim, but there is another fault in this system - what if a file being called by the BAT file doesn’t exist on the target system? I know of no way to handle exceptions in batch files. It would also be nice to have a Linux method of converting .sh files into binaries.
-
Tim Fehlman Says:
March 19th, 2007 at 3:00 pmJonathan,
That is definitely an issue that this solution is not intended to resolve because you would have that same issue with the batch file run natively. It is a problem with the batch file, not the compiled script.That being said, it is possible to add these required third party applications to the compiled exe by simply adding more FileInstall commands.
Tim
-
John May Says:
March 19th, 2007 at 5:01 pmThere are commercial ways to convert a batch file to exe.
-
onlineapps.newsvine.com - Online Apps Says:
March 20th, 2007 at 12:17 amOnline Apps’ Apps[IMG ]
-
Explore And Create Says:
April 2nd, 2007 at 1:52 pmTrackback link - http://www.DailyCupOfTech.com/2007/03/19/batch-file-to-executable/trackback/ Email this • Subscribe by email • Subscribe to this feed
-
m0nk3y_I3unz Says:
June 24th, 2007 at 7:12 pmActually, a converter wouldn’t be all that much harder. Just create a script that reads the BAT file as a text file and get the lines. then add the COMSPEC commands and whatever, save it as an .AU3 and run AUT2EXE with the params. To get the params, make a stoopid script, save it, and in SciTE, goto tools and then click compile. the console will give the right ones.
m0nk3y_I3unz
P.S. Im creating this application now - gonna upload it to HBH. my name here is the same on there.
-
William Says:
September 24th, 2007 at 1:38 amYou can use a program in Windows XP to convert Batch files to exe, The program is in C:\windows\System32 folder look for the file named ieexpress.exe here is some directons i got from a web site?
Step 1
Navigate to C:\Windows\System32 and locate the file named IEXPRESS.EXEStep 2
Double Click to launch IEXPRESS.EXEStep 3
You will be presented with the initial welcome screen and be given two choices. Select “Create new Self Extraction Directive file.” Click Next.Step 4
Next you will be presented with the Package Purpose screen. For our purposes select “Extract Files and run an installation command” and click the Next button.Step 5
You will be presented with the Package Title screen, which will give you the opportunity to give your project a name. If you are so inclined give it a meaningful name. If like me you are never going to come back to this, name it whatever you want.Step 6
You will next be presented with the Confirmation Prompt Screen. We would like the batch file to just be extracted and run so just choose “No Prompt” and click the Next Button.Step 7
You are presented with the License Agreement window. If you don’t want your users to have to answer a prompt select “Do not display a license.”Step 8
The Packaged Files window is where you will select your batch file (or .vbs). Click the Add button and browse to your desired file. Then click next.Step 9
Here you are presented with a window titled Install Program to Launch. Use the drop down control next to “Install Program and choose the only option that will be present, the .bat or .vbs file that you chose in the previous window.Step 10
The Show Window screen is next. I didn’t want my users to be prompted in any way so I chose Hidden. Click Next.Step 11
No Finished Message for my users. Select “No message” and choose Next.Step 12
The Package Name and Options window is where the new .exe specified. Type in a path or browse to the folder you would like your .exe in, type a name in the file name box and click save. Also check the box that says “Hide File Extraction Progress Animation from User.” If you’re worried about long file names go ahead and click the other box as well.Step 13
Since we really aren’t installing anything we probably want to tell the Configure Restart window to not restart. So choose the option that says “No restart” and hit Next.Step 14
This window is where you have a chance to save all of the options you have chosen into a project file so that if necessary you may later return and make modifications. I have no need to retain the file, but if you would like to be able to come back to it, by all means choose “Save Self Extraction Directive (SED) file” and tell it where to put it. As always, click Next.Step 15
Here’s where you’re new .exe is born, on the Create Package screen. Explore to the directory you told it to put the file in, click Next and then watch your little .exe’s first moments as it pops into the big digital world.Step 16
You’re done! Click finish and go try it out. Pin it directly to the start menu. Point a shortcut to it and pin that to the start menu. Most importantly, script it and see how slick it is. If you’re not familiar with how to script start menu pinning the scripting guys will tell you how. Check it out here! -
AjS Says:
March 25th, 2008 at 5:08 amhi all
i am running a batch file to run exe files which exist at different location. i am using the code like this,chdir (path)
file.exe -
Jakash3 Says:
September 24th, 2008 at 11:46 pmIExpress.EXE shouldn’t really be used to convert batch files into executible files because it doesn’t work well. iexpress.exe runs batch file with command.com, an older version of cmd so the .bat files wouldn’t run the way you wanted it unless it was coded in old MS-DOS text. It would be better if you compiled the .bat file into .exe with a converter found here:
http://www.download.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html?tag=mncol&cdlPid=10888479then add that direct compiled executible to iexpress which will package it, then it will work right.
watch this video from youtube for an excelent demonstration of batch files and iexpress.exe here
WATCH THIS VIDEO:

