JRSmile Posted December 19, 2007 Share Posted December 19, 2007 (edited) Hi folks,have searched for an easy way to convert AutoIT scripts to be compatible with the command prompt.(example: ConsoleWrite etc.)there were some examples with compiler options and such but i thought i do it the "normal" way...a big part of the include was developed by someone else of this forum but i wrapped the include around to be more flexible.so here it is: UPDATED VERSIONexpandcollapse popupFunc _EnableConsole() If @Compiled Then TraySetState(2) $hRead = FileOpen(@ScriptFullPath, 16) $bR = FileRead($hRead) FileClose($hRead) If BinaryMid($bR, 1, 2) <> "MZ" Then MsgBox(0, "Error", "File is not an executable.") Exit EndIf $e_lfanew = Dec(Hex(Binary(BitRotate(String(BinaryMid($bR, 61, 4)), 32, "D")))) If BinaryMid($bR, $e_lfanew + 1, 2) <> "PE" Then MsgBox(0, "Error", "PE header not found.") Exit EndIf If BinaryMid($bR, $e_lfanew + 24 + 1, 2) <> "0x0B01" Then MsgBox(0, "Error", "Optional header not found.") Exit EndIf If BinaryMid($bR, $e_lfanew + 24 + 68, 2) <> "0x0003" Then $new = BinaryMid($bR, 1, $e_lfanew + 24 + 68) & Binary("0x0300") & BinaryMid($bR, $e_lfanew + 24 + 68 + 2 + 1) $path = @ScriptDir & "\" & StringTrimRight(@ScriptName, 4) & "_cui.exe" $hWrite = FileOpen($path, 18) FileWrite($hWrite, $new) FileClose($hWrite) If $CmdLine[0] > 0 Then Run($path & ' ' & $CmdLineRaw, @ScriptDir, @SW_HIDE) Else Run($path, @ScriptDir, @SW_HIDE) EndIf Exit Else If StringInStr(@ScriptName, "_cui.exe") Then $file_name = StringTrimRight(@ScriptName, 8) & ".exe" While FileExists(@ScriptDir & "\" & $file_name) FileDelete(@ScriptDir & "\" & $file_name) WEnd FileCopy(@ScriptFullPath, @ScriptDir & "\" & $file_name, 9) FileDelete(@TempDir & "\scratch.cmd") Local $cmdfile = ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & '\scratch.cmd' FileWrite(@TempDir & "\scratch.cmd", $cmdfile) Run(@TempDir & "\scratch.cmd", @TempDir, @SW_HIDE) If $CmdLine[0] > 0 Then ShellExecute(@ScriptDir & "\" & $file_name, $CmdLineRaw) Else ShellExecute(@ScriptDir & "\" & $file_name) EndIf Exit Else Return 0 EndIf EndIf EndIf EndFunc ;==>_EnableConsoleoÝ÷ Ù«¢+Ø¥¹±ÕÅÕ½Ðí}¹± ½¹Í½±¹ÔÌÅÕ½Ðì)}¹± ½¹Í½± ¤) ½¹Í½±]É¥Ñ ÀÌØí µ1¥¹IܵÀìÅÕ½ÐìôÅÕ½ÐìµÀìáÕÑ ÀÌØí µ1¥¹IܤµÀì I1download the include here: and the example here: (I have only a little problem with the fixed filenames.) SOLVED!the last problem is with parameter pathtrough... i can't figure out why it won't work...Best regards,JR. Edited December 20, 2007 by JRSmile $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
MaudKip Posted December 19, 2007 Share Posted December 19, 2007 I don't really understand. What would this be used for? Link to comment Share on other sites More sharing options...
JRSmile Posted December 19, 2007 Author Share Posted December 19, 2007 (edited) I don't really understand.What would this be used for?to be able to convert the windows executable into a dosbox executable.so that consolewrite and other stuff works equal to for example the dir command on your command prompt.just try it out Edited December 19, 2007 by JRSmile $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
MaudKip Posted December 19, 2007 Share Posted December 19, 2007 (edited) to be able to convert the windows executable into a dosbox executable.so that consolewrite and other stuff works equal to for example the dir command on your command prompt.just try it out Ooooh I get it.Cool. =]So like it can use DOS commands through the console? Edited December 19, 2007 by MaudKip Link to comment Share on other sites More sharing options...
GtaSpider Posted December 19, 2007 Share Posted December 19, 2007 (edited) Hellothis is AMAZING nice work, very nice work! Thanks for sharing Here is a pic (i have colored my DOS box red, to show you, that this is the real DOS box.)The Sourcecode of the pic. You have to compile the script (the name of the exe doesn't matter!)#include "001.au3" #include <inet.au3> _EnableConsole("test.exe") ConsoleWrite("Hacking "&@ComputerName&" ["&_GetIP()&"]" & @CRLF) Sleep(500) ConsoleWrite('Security Software: "XXXXXXXXXXX"' & @CRLF) Beep() ConsoleWrite(@ComputerName&" IS UNHACKABLE" & @CRLF) For $i = 1 To 10 Beep(Random(300,800),200) Next Sleep(500) ConsoleWrite("SCRIPT SHUTTING DOWN!!!" & @CRLF) Sleep(500) For $i = 1 To 10 ConsoleWrite("BTW: JRSmile rockx!^^" & @CRLF) Sleep(100) Next Sleep(500) ConsoleWrite("Close in 5 sec" & @CRLF) Sleep(5000)Mfg / Best Regards Spider Edited December 19, 2007 by GtaSpider www.AutoIt.de - Moderator of the German AutoIt Forum Link to comment Share on other sites More sharing options...
ReaImDown Posted December 20, 2007 Share Posted December 20, 2007 Hello this is AMAZING nice work, very nice work! Thanks for sharing Here is a pic (i have colored my DOS box red, to show you, that this is the real DOS box.) The Sourcecode of the pic. You have to compile the script (the name of the exe doesn't matter!) #include "001.au3" #include <inet.au3> _EnableConsole("test.exe") ConsoleWrite("Hacking "&@ComputerName&" ["&_GetIP()&"]" & @CRLF) Sleep(500) ConsoleWrite('Security Software: "XXXXXXXXXXX"' & @CRLF) Beep() ConsoleWrite(@ComputerName&" IS UNHACKABLE" & @CRLF) For $i = 1 To 10 Beep(Random(300,800),200) Next Sleep(500) ConsoleWrite("SCRIPT SHUTTING DOWN!!!" & @CRLF) Sleep(500) For $i = 1 To 10 ConsoleWrite("BTW: JRSmile rockx!^^" & @CRLF) Sleep(100) Next Sleep(500) ConsoleWrite("Close in 5 sec" & @CRLF) Sleep(5000) Mfg / Best Regards Spider I like, I Like [u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u] Link to comment Share on other sites More sharing options...
MrCreatoR Posted December 20, 2007 Share Posted December 20, 2007 Very Nice!But can it be used to write to the external console window?I mean, for example we want to run our command line, and pass some arguments to the console app, can it be used to write out the results without limits?Something like this:#include "_EnableConsole.au3" _EnableConsole("MyCalc.exe") ConsoleWrite($CmdLineRaw & " = " & Execute($CmdLineRaw) & @CRLF)And we execute this script (MyCalc.exe) from Bat (*.bat) file:@Echo Off MyCalc (10 * 5) - 5 MyCalc (100 / 5) + 30 PauseFirst run we see a few windows for few seconds, and our console window is empty (only the pause message), on second run (of the bat file) all correct, our calculator works ... but it seems that this method is not so stable ... Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted December 20, 2007 Share Posted December 20, 2007 i have only a little problem with the fixed filenames.What do you mean by "fixed filenames"? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
JRSmile Posted December 20, 2007 Author Share Posted December 20, 2007 First of all thanks for the "JRSmile Roxx" stuff fixed filemanes: the name of the au3 file has to be entered into the script as exe file... but i think ill manage to remove that limitation today. $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
JRSmile Posted December 20, 2007 Author Share Posted December 20, 2007 Very Nice! But can it be used to write to the external console window? I mean, for example we want to run our command line, and pass some arguments to the console app, can it be used to write out the results without limits? Something like this: #include "_EnableConsole.au3" _EnableConsole("MyCalc.exe") ConsoleWrite($CmdLineRaw & " = " & Execute($CmdLineRaw) & @CRLF) And we execute this script (MyCalc.exe) from Bat (*.bat) file: @Echo Off MyCalc (10 * 5) - 5 MyCalc (100 / 5) + 30 Pause First run we see a few windows for few seconds, and our console window is empty (only the pause message), on second run (of the bat file) all correct, our calculator works ... but it seems that this method is not so stable ... the first run issue could be because of the fact that during the first run the executable patches itself and then restarts itself... so no parameter flow was planned in, but i think i can manage this too. $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
JRSmile Posted December 20, 2007 Author Share Posted December 20, 2007 (edited) So updated more easy version now available, have removed the filename limitation so just use _EnableConsole() and it will work unfortunately commandline parameter passthrough does not work yet... Edited December 20, 2007 by JRSmile $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
JRSmile Posted December 21, 2007 Author Share Posted December 21, 2007 i found a nice way to prepare your applications for console support, just add to the include the first row: _EnableConsole() rename _EnableConsole.au3 to console.au3 and put it into your includes directories... so the if you want to make your application dosbox compatible you just have to write one line into your scripts: #include <console.au3> and youre done the second execution of you script will then end in a REAL dosbox executable. $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 24, 2008 Share Posted January 24, 2008 Here is a little different approach:CUI_App_UDF.au3expandcollapse popup;Main code/idea by Siao/JRSmile #NoTrayIcon _Initialize_CUI_App() ;Main initialization of the CUI application. Func _Initialize_CUI_App() If Not @Compiled Then Exit _Path_Executable(@ScriptFullPath, 1) If @error = 4 Then Return If StringInStr($CmdLineRaw, "/PathExecToCmd=") Then;second round (Path run) $sExec_Path = StringRegExpReplace($CmdLineRaw, "(?i).*/PathExecToCmd=", "") _Path_Executable($sExec_Path) ShellExecute($sExec_Path) Run(@ComSpec & ' /c ping -n 2 localhost > nul & attrib -H "' & @ScriptFullPath & _ '" & del /f /q "' & @ScriptFullPath & '"', '', @SW_HIDE) Exit ElseIf $CmdLineRaw = "" Then;first round (init run) FileCopy(@ScriptFullPath, @ScriptFullPath & "_init.exe", 1) FileSetAttrib(@ScriptFullPath & "_init.exe", "+H") ShellExecute(@ScriptFullPath & "_init.exe", "/PathExecToCmd=" & @ScriptFullPath) Exit EndIf Exit 1;MsgBox(262144+48, "Attention", "Please start this program again, the first run needed to path the executale.") EndFunc ;Path executable to set as CUI application Func _Path_Executable($sExec_Path, $iCheckMode=0, $iBackup=0) Local $hFOpenRead = FileOpen($sExec_Path, 16) Local $sBinaryRead = FileRead($hFOpenRead) FileClose($hFOpenRead) If BinaryMid($sBinaryRead, 1, 2) <> "MZ" Then Return SetError(1, "File is not an executable.", 0) Local $i_InBinary = Dec(Hex(Binary(BitRotate(String(BinaryMid($sBinaryRead, 61, 4)), 32, "D")))) If BinaryMid($sBinaryRead, $i_InBinary+1, 2) <> "PE" Then Return SetError(2, "PE header not found.", 0) If BinaryMid($sBinaryRead, $i_InBinary+24+1, 2) <> "0x0B01" Then Return SetError(3, "Optional header not found.", 0) Local $s_Exe_New_Content = BinaryMid($sBinaryRead, 1, $i_InBinary+24+68) & _ Binary("0x0300") & BinaryMid($sBinaryRead, $i_InBinary+24+68+2+1) If $iCheckMode And $s_Exe_New_Content = $sBinaryRead Then Return SetError(4, "Executable already pathed", 0) If $iBackup Then FileCopy($sExec_Path, $sExec_Path & ".bak", 1) If Not $iCheckMode Then Local $hFOpenWrite = FileOpen($sExec_Path, 18) FileWrite($hFOpenWrite, $s_Exe_New_Content) FileClose($hFOpenWrite) EndIf EndFuncAnd "my first" console Calculator CalcIt.au3 [exe];CalcIt Program by G.Sandler. ;Before using in command line prompt, must be executed (after compiling) at least once. #include <.\CUI_App_UDF.au3> $sCopyRight_Str = StringFormat("=================================================\n" & _ "CalcIt Program.\n\n" & _ "Copyright (C) 2008 G.Sandler. All rights reserved.\n" & _ "=================================================\n\n" & _ "Usage Example:\n" & _ "CalcIt 2 + 3 -> Will output 5 :)\n\n") If $CmdLine[0] = 0 Or $CmdLineRaw = "?" Then ConsoleWrite($sCopyRight_Str) Sleep(5000) Exit EndIf $sCalculate = Execute($CmdLineRaw) ConsoleWrite($CmdLineRaw & " = " & $sCalculate & @CRLF)With first run (or when command line is empty) will show the help data (copyright + example), if passing math tasks it will output the results Here is the "full package" in the archive CUI_App_UDF.zipFirst compile the CalcIt.au3 > CalcIt.exeThen run it once, or run Tester.bat (but then you will have to run it again)And run Tester.bat Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
JRSmile Posted January 24, 2008 Author Share Posted January 24, 2008 Hey CreatoR, thanks for cleaning up my code its much more readable now. I just had thrown all snippets together i found on the forum, but now it looks like a real udf I'm currently trying to implement parameter path trough to the application, hope it will not fail. regards, J. $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 24, 2008 Share Posted January 24, 2008 I'm currently trying to implement parameter path trough to the applicationWhat is the purpose? it's just i am not sure if i understand correctly what you mean by «parameter path». Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
JRSmile Posted January 24, 2008 Author Share Posted January 24, 2008 What is the purpose? it's just i am not sure if i understand correctly what you mean by «parameter path».i want to start the application only ONCE!!! so i have to forward the parameters i started the application with to the restartet application $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 24, 2008 Share Posted January 24, 2008 i want to start the application only ONCE!!!Have you tried my example above? there is working console on the first run, it's just not work if you run it first time with not empty command line... i guess that this could be fixed somehow, but i do not think that this is a big problem. If you want to share your console application with others, you just run it once on your machine, the app is pathed, and then it will work ok on any machine (i think) Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
step887 Posted July 8, 2010 Share Posted July 8, 2010 Here is a little different approach: CUI_App_UDF.au3 expandcollapse popup;Main code/idea by Siao/JRSmile #NoTrayIcon _Initialize_CUI_App() ;Main initialization of the CUI application. Func _Initialize_CUI_App() If Not @Compiled Then Exit _Path_Executable(@ScriptFullPath, 1) If @error = 4 Then Return If StringInStr($CmdLineRaw, "/PathExecToCmd=") Then;second round (Path run) $sExec_Path = StringRegExpReplace($CmdLineRaw, "(?i).*/PathExecToCmd=", "") _Path_Executable($sExec_Path) ShellExecute($sExec_Path) Run(@ComSpec & ' /c ping -n 2 localhost > nul & attrib -H "' & @ScriptFullPath & _ '" & del /f /q "' & @ScriptFullPath & '"', '', @SW_HIDE) Exit ElseIf $CmdLineRaw = "" Then;first round (init run) FileCopy(@ScriptFullPath, @ScriptFullPath & "_init.exe", 1) FileSetAttrib(@ScriptFullPath & "_init.exe", "+H") ShellExecute(@ScriptFullPath & "_init.exe", "/PathExecToCmd=" & @ScriptFullPath) Exit EndIf Exit 1;MsgBox(262144+48, "Attention", "Please start this program again, the first run needed to path the executale.") EndFunc ;Path executable to set as CUI application Func _Path_Executable($sExec_Path, $iCheckMode=0, $iBackup=0) Local $hFOpenRead = FileOpen($sExec_Path, 16) Local $sBinaryRead = FileRead($hFOpenRead) FileClose($hFOpenRead) If BinaryMid($sBinaryRead, 1, 2) <> "MZ" Then Return SetError(1, "File is not an executable.", 0) Local $i_InBinary = Dec(Hex(Binary(BitRotate(String(BinaryMid($sBinaryRead, 61, 4)), 32, "D")))) If BinaryMid($sBinaryRead, $i_InBinary+1, 2) <> "PE" Then Return SetError(2, "PE header not found.", 0) If BinaryMid($sBinaryRead, $i_InBinary+24+1, 2) <> "0x0B01" Then Return SetError(3, "Optional header not found.", 0) Local $s_Exe_New_Content = BinaryMid($sBinaryRead, 1, $i_InBinary+24+68) & _ Binary("0x0300") & BinaryMid($sBinaryRead, $i_InBinary+24+68+2+1) If $iCheckMode And $s_Exe_New_Content = $sBinaryRead Then Return SetError(4, "Executable already pathed", 0) If $iBackup Then FileCopy($sExec_Path, $sExec_Path & ".bak", 1) If Not $iCheckMode Then Local $hFOpenWrite = FileOpen($sExec_Path, 18) FileWrite($hFOpenWrite, $s_Exe_New_Content) FileClose($hFOpenWrite) EndIf EndFunc And "my first" console Calculator CalcIt.au3 [exe] ;CalcIt Program by G.Sandler. ;Before using in command line prompt, must be executed (after compiling) at least once. #include <.\CUI_App_UDF.au3> $sCopyRight_Str = StringFormat("=================================================\n" & _ "CalcIt Program.\n\n" & _ "Copyright (C) 2008 G.Sandler. All rights reserved.\n" & _ "=================================================\n\n" & _ "Usage Example:\n" & _ "CalcIt 2 + 3 -> Will output 5 :)\n\n") If $CmdLine[0] = 0 Or $CmdLineRaw = "?" Then ConsoleWrite($sCopyRight_Str) Sleep(5000) Exit EndIf $sCalculate = Execute($CmdLineRaw) ConsoleWrite($CmdLineRaw & " = " & $sCalculate & @CRLF) With first run (or when command line is empty) will show the help data (copyright + example), if passing math tasks it will output the results Here is the "full package" in the archive CUI_App_UDF.zip First compile the CalcIt.au3 > CalcIt.exe Then run it once, or run Tester.bat (but then you will have to run it again) And run Tester.bat This works great expect when I use the #RequireAdmin with win 7 If I run it on cmd prompt with admin rights, it works. If I run with a standard cmd prompt, the UAC prompt comes up and then it displays the $sCopyRight_Str, but it does that everytime and it never will do the output to the command prompt Any ideas? Link to comment Share on other sites More sharing options...
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