Sign in to follow this  
Followers 0
Geo0w

How runing autoit scripts with console

5 posts in this topic

#1 ·  Posted (edited)

Well,

I discovered the AutoIt langage two days ago thanks to a friend, and the first thing that I wanted to do is a sample script that displays "Hello World" in a command line interface (cmd.exe). But it wasn't working, even if I compiled the script...

I found a solution - maybe you've found it and I don't look for 'cause I'm lost in this forum... - to make the script working.

First, you have a sample code :

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


ConsoleWrite("Foobar!")

You save a file named "hello.au3" ; then a right click & "Compile File" to Compile it...

Now, when you try to launch the program in the cli, it fails... Why ?

Simply because there's a flag in the header of the program which means that the program is a "GUI". You simply have to edit this flag in order to mean that it's a console program.

Take an hexadecimal editor, and you see the "02" value at the offset 0x154. Set "03" and your script will perfectly work!

In fact, 02 and 03 are represented by a constant in many langages like C ; 02 means GUI & 03 means CUI.

For a next release, why don't implementing a feature that generate an exe file with the appropriate constant ?

That's all.

PS : I'm French, I wish I could explain it better if it's not very clean.

Edited by Geo0w

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

That's such a fantastic feature that it has been present since AutoIt 3.2.12.1

Take a look at the Aut2Exe gui or commandline switches, to build to a cui capable program.

What version are you using?

Edited by Mobius

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

its fairly clean lol... you should read some of the other posts (including some of mine) on these forums... WAY worse, but uh... isnt there an option on scite --> tools --> compile --> and then the checkbox (Create CUI instead of GUI exe)

EDIT mobius beat me to it XD

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I didn't know. I apologize. >_<

I use the latest version.

Edited by Geo0w

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

what you posted was pretty sound.

Just remember that the subsystem byte offset is relative to the 'PE' word(17744) hex(5045)

within the Executable header, and is not static throughout all win32 binaries / versions of AutoIt3.

Check it out for yourself, take 2 totally different programs (notepad and an Au3 binary for example)

and pop em into your hex editor, note down the offsets of the 'PE' word in each of the headers.

Are they the same?

Still in your hex editor, read 91 bytes from the end of the 'PE' word for both programs,

it is here you will find the subsystem byte flag, which should be a value between 1 & 14 .

Or like you pointed out, the most likely values are 2(win) & 3(con).

Ed: fuzzy

Edited by Mobius

Share this post


Link to post
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
Sign in to follow this  
Followers 0