Astuces

De Wiki AutoIt Français
Aller à : navigation, rechercher

La conception / traduction de cette page est toujours en cours.


Here you'll find a categorical listing of scripts created by AutoIt users. Also see the Exemples page.

General Programming

Automation

Examples specific to Windows automation.

Windows Management Instrumentation

Some examples on how to use WMI.

Networking Scripts

Examples of networking

GUI and graphics

Examples of simple GUI and custom windows. Also, 2D and 3D game-like examples.

Sound

Sound scripts and functions.

AutoIt3Wrapper

AutoIt3Wrapper directives allow much greater and in depth control of your resulting programs. Some of these can be very useful under different circumstances.

Stripping excess code

For instance, if you have several includes, then you can often strip thousands of lines from your program using obfuscator:

#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0


On a medium sized script, results are often like this:

>Running Obfuscator (1.0.27.0)  from:C:\Program Files\AutoIt3\SciTE cmdline:
- Iteration 1 Strip Functions result: Output  2580 lines and stripped 6741 lines
- Iteration 2 Strip Variables result: Output  1585 lines and stripped 950 lines
- Iteration 3 Strip Variables result: Output  1566 lines and stripped 19 lines
- Iteration 4 Start the actual Obfuscation.
+> Source    26190 lines 1447980 Characters.
+> Stripped  7710 Func/Var lines and  16862 comment lines, Total 1373871 Characters.
+> Saved     93% lines 94% Characters.
+> Obfuscator v1.0.27.0 finished obfuscating 1566 lines, created:C:\MyScript_Obfuscated.au3


Using ResHacker

ResHacker is a very important programming tool for extracting and adding resources into executables. It has a very simple command line interface that allows it to be used easily using the "Run_After" directive. Adding a picture to an executable could be done like this:

#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, MyPicture.bmp, BITMAP, RESOURCENAME, 0


  • NB:* Reshacker.exe MUST be copied into the script directory for this to work!

If you then want to use the resources in your code, there is an excellent Resources UDF which will allow you to access the resources from within the exe.

Adding original source code

When using the above tip on stripping excess code, the new source is not readable. As a result, using the standard directive for saving the source:

#AutoIt3Wrapper_Res_SaveSource=y

Would add the obfuscated code to the exe, which is not the desired result. The solution is to add it in manually. This code does not require any editing, so you can just copy and paste it in:

#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, %scriptfile%.au3, RCDATA, SOURCE, 0


Creating a Version directory

When compiling, it is very possible that you want to go back to a previous version. If so, then it is neat to have a directory which will store all previous builds, without the need for you to manually copy and paste every time! Make sure you add these directives in last (after adding resources) as they might not be included in the copied result.

#AutoIt3Wrapper_Run_After=md "%scriptdir%\Versions\%fileversion%"
#AutoIt3Wrapper_Run_After=copy "%in%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.au3"
#AutoIt3Wrapper_Run_After=copy "%out%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.exe"


Running the exe on build

Often you are building as a test, so to have to open up explorer to get the exe is a pain, furthermore, unless you have a program to do it (or its a console program) you will not be able to read console info such as the debug messages you put in the exe. The solution is simple:

#AutoIt3Wrapper_Run_After="%out%"

This will run the program and read the console output to the SciTE debug frame.

Extended Reshacker Info

ResHacker doesn't always return with a return code (rc) of not 0 if it fails, to get that info you need to read the ResHacker.log file that is created. This is also pretty simple to do:

#AutoIt3Wrapper_Run_After=ResHacker.exe -add %out%, %out%, MyPicture.bmp, BITMAP, RESOURCENAME, 0
#AutoIt3Wrapper_Run_After=TYPE ResHacker.log


The new output now looks like this:

>Running:ResHacker.exe -add C:\MyScript.exe, C:\MyScript.exe, MyPicture.bmp, BITMAP, RESOURCENAME, 0
>ResHacker.exe -add C:\MyScript.exe, C:\MyScript.exe, MyPicture.bmp, BITMAP, RESOURCENAME, 0 Ended   rc:0
>Running:TYPE ResHacker.log
[19 Jan 2010, 21:26:22]
ResHacker.exe  -add C:\MyScript.exe, C:\MyScript.exe, MyPicture.bmp, BITMAP, RESOURCENAME, 0
 Added: BITMAP,RESOURCENAME,0

Commands completed
>TYPE ResHacker.log Ended   rc:0


And an example of it showing an error:

>ResHacker.exe -add C:\MyScript.exe, C:\MyScript.exe, MyPicture.bmp, BITMAP, RESOURCENAME, 0 Ended   rc:0
>Running:TYPE ResHacker.log
[19 Jan 2010, 21:32:10]
ResHacker.exe  -add C:\MyScript.exe, C:\MyScript.exe, MyPicture.bmp, BITMAP, RESOURCENAME, 0
Error: "MyPicture.bmp" does not exist
>TYPE ResHacker.log Ended   rc:0

As you can see, Reshacker on its own returns rc: 0, usually indicating no error. This would have gone completely unnoticed except for the log file, which shows the error and an explanation.

Other Run_After and Run_Before commands

You can use any cmd commands you like in the Run_After and Run_Before directives. Examples such as "TYPE" have been shown above. For a more complete list the following website is very useful:

[1]