stev379 Posted March 24, 2009 Posted March 24, 2009 Our SMS Admin was asking me for simple batch files compiled into exe's so I wrote a GUI to enter one line batch file commands and compile into an exe. I thought I saw something on the forum that does this or something similar, but we only needed something very basic. We jump from one computer to another fairly often so being able to do this at a machine that already has AutoIT installed isn't always feasible. I packed the necessary AutoIT files into the exe so he can run the BatchCompiler GUI anywhere, type in a 1 line batch command and compile even when AutoIT is not installed. See the "_CreateDirs()" function at the bottom of the script so you can put the files in place and set your paths. Any improvements\suggestions are welcome. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <File.au3> ;---------------------------------------------------------------------- ; Script Author: Steve Bradham - stev379 ; Creation Date: June 18, 2008 ; Script Function: Create and compile a batch command into an exe ; ; ; Function: Compile a one line batch file command line into an exe ; Instructions: Type a script name Example TestCompiler.au3 ; Enter a one line batch command exactly as you would for a batch file ; Click CompileEXE to compile your batch command into an executable. The executable will be ; placed in your script's directory ; ; NOTES: Add a fileinstall for the Aut2Exe folder and if statements to check for it. - Done ; ; Requisites: See the _CreateDirs() function at the bottom of the script for FileInstall requisites. ; You must have the directories and AutoIT files in place when you compiled the script. ; ;---------------------------------------------------------------------- Opt('MustDeclareVars', 1) Dim $msg, $cmd, $cmd_RD Dim $btn_RUNtest, $btn_CompileBAT, $btn_CompileEXE Dim $File, $Filename, $filewrite, $filename_RD, $fileToCompile, $fileCompiled Dim $LineCount, $dest Dim $i Dim $Scrapfile, $ScrapFileRD, $ScrapfileToRD Dim $Edit, $Edit_RD Global $Script Global $Scriptname, $ScriptnameEXT _CreateDirs() _CreateCompiledEXE() Func _CreateCompiledEXE() Local $msg GUICreate("Compile batch command into a .exe", 550, 500) GUICtrlCreateLabel("Enter a one line batch command to test your syntax", 20, 10, 250, 20) $cmd = GUICtrlCreateInput("", 20, 30, 350, 20) GUICtrlCreateLabel("Enter Filename to create - You must use a .BAT extension to compile a BAT.", 20, 107, 400, 20) GUICtrlCreateLabel("You must use a .AU3 extension to compile an EXE.", 138, 125, 400, 20) $filename = GUICtrlCreateInput("", 20, 145, 350, 20) $btn_RUNtest = GUICtrlCreateButton("Run Test", 30, 55) $btn_CompileBAT = GUICtrlCreateButton("CompileBAT", 30, 175) $btn_CompileEXE = GUICtrlCreateButton("CompileEXE", 105, 175) GUICtrlCreateLabel("Enter text exactly as you would for a batch file", 20, 225, 250, 20) $Edit = GUICtrlCreateEdit("", 20, 250, 500, 230) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $btn_RUNtest $cmd_RD = GUICtrlRead($cmd) Run(@ComSpec & " /c " & $cmd_RD) Case $msg = $btn_CompileBAT $Edit_RD = GUICtrlRead($edit) $filename_RD = GUICtrlRead($filename) If Not _FileCreate($filename_RD) Then MsgBox(4096, "Error", @error) Sleep(500) $filewrite = FileOpen($filename_RD, 1) FileWrite($filewrite, $edit_RD) FileClose($filewrite) Case $msg = $btn_CompileEXE $Edit_RD = GUICtrlRead($Edit) $Scrapfile = "Scrapfile.txt" If Not _FileCreate($Scrapfile) Then MsgBox(4096, "Error", @error) Sleep(500) $filewrite = FileOpen($Scrapfile, 1) FileWrite($filewrite, $Edit_RD) FileClose($filewrite) $filename_RD = GUICtrlRead($filename) If Not _Filecreate($filename_RD) Then MsgBox(4096, "Error", @error) $LineCount = _FileCountLines($Scrapfile) $ScrapfileToRD = FileOpen($Scrapfile, 0) $fileToCompile = FileOpen($filename_RD, 1) FileWriteLine($fileToCompile, '#NoTrayIcon') For $i = 1 to $LineCount $ScrapFileRD = FileReadLine($ScrapfileToRD, $i) Sleep(50) FileWriteLine($fileToCompile, 'Run(@comspec & '' /c ' & $ScrapFileRD & ''','''','''')') Next FileClose($ScrapfileToRD) FileClose($fileToCompile) Sleep(3000) _Compile(_RemoveExtension($filename_RD)) EndSelect WEnd GUIDelete() EndFunc ;_CreateRUN FileDelete($Scrapfile) FileDelete($filename_RD) Func _Compile($Scriptname) Run("C:\Scripts\Aut2Exe\Aut2Exe.exe /in " & @ScriptDir & "\" & $Scriptname & ".au3 /out " & _ @ScriptDir & "\" & $Scriptname & ".exe /icon C:\Scripts\Aut2Exe\Icons\SETUP03.ICO") EndFunc ;_Compile Func _RemoveExtension($ScriptnameEXT) $Scriptname = stringleft($ScriptnameEXT, stringlen($ScriptnameEXT)-4) Return $Scriptname EndFunc ;_RemoveExtension Func _CreateDirs() If Not FileExists ("C:\Scripts\Aut2Exe") Then DirCreate("C:\Scripts\Aut2Exe\Icons") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\Aut2exe.exe", "C:\Scripts\Aut2Exe\Aut2exe.exe") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\Aut2exe_x64.exe", "C:\Scripts\Aut2Exe\Aut2exe_x64.exe") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\Aut2exeA.exe", "C:\Scripts\Aut2Exe\Aut2exeA.exe") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\AutoItASC.bin", "C:\Scripts\Aut2Exe\AutoItASC.bin") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\AutoItSC.bin", "C:\Scripts\Aut2Exe\AutoItSC.bin") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\AutoItSC_x64.bin", "C:\Scripts\Aut2Exe\AutoItSC_x64.bin") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\upx.exe", "C:\Scripts\Aut2Exe\upx.exe") FileInstall([ENTER YOUR SCRIPT DIRECTORY HERE]\Icons\Setup03.ico", "C:\Scripts\Aut2Exe\Icons\Setup03.ico") EndIf EndFunc ;_CreateDirsBatchCompiler4.1.1.au3.txt
jvanegmond Posted March 24, 2009 Posted March 24, 2009 Why specifically for one line batch scripts? Why not add support for multi-line batch scripts? github.com/jvanegmond
yehia Posted March 24, 2009 Posted March 24, 2009 yes none of my bats are one line My Scripts:IE New UDFsElastic images moving under mouse (with a happy valentine's example)_FileRemoveLine
Ascend4nt Posted March 24, 2009 Posted March 24, 2009 There's a neat program called Quick Batch File Compiler that you could use. Unfortunately, it's a pay-for program. But at least there's not a big memory overhead. Although, I'm not sure what overhead a CUI version of a compiled AutoIT program uses. And I think that actually would make more sense for your compiled exe's to be Console applications (compiling with the /console switch I believe) My contributions: Reveal hidden contents Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Bozzman Posted March 24, 2009 Posted March 24, 2009 just to help you outhttp://www.f2ko.de/English/b2e/download.phplet your program use this cmdline tool at least its multy line support
isuru Posted July 31, 2015 Posted July 31, 2015 Hi guysfew days ago i was searching for the same solution.i found this amazing software Batch Compiler Its is more of an IDE for batch files.It has everything we need to develop a batch exe. best part is that is has a debugger to check syntax for errors.hope this helps!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now