Jump to content

AutoIT Reloaded


JRSmile
 Share

Recommended Posts

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 VERSION

Func _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ܤµÀì
I1

download 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 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

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 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

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 by MaudKip
Link to comment
Share on other sites

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.)

Posted Image

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 by GtaSpider

www.AutoIt.de - Moderator of the German AutoIt Forum

 

Link to comment
Share on other sites

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.)

Posted Image

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

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 ^_^ ...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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

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

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 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

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. :P

$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

  • 1 month later...

Here is a little different approach:

CUI_App_UDF.au3

;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 :P

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 :D

Here is the "full package" in the archive :P

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 ;)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hey CreatoR, thanks for cleaning up my code :D 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 :P

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

I'm currently trying to implement parameter path trough to the application

What 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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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 :D

$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

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) :D

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 2 years later...

Here is a little different approach:

CUI_App_UDF.au3

;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 :blink:

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 :P

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...