AutoIT Script for Windows Users

Discussion related to AES Crypt, the file encryption software for Windows, Linux, Mac, and Java.
Post Reply
Winfried
Posts: 5
Joined: Wed Mar 01, 2023 1:47 pm

AutoIT Script for Windows Users

Post by Winfried »

For Windows users, here's an Autoit script that 1) prompts the user for the password and the AES-encrypted file, and 2) decrypts it, opens the default text editor, and pastes the output therein:

Code: Select all

;Edit the following line to match the notepad.exe on your computer:
;WinWait("[TITLE:Untitled - Notepad2-mod; CLASS:Notepad2]")

#include <Array.au3>
#include <AutoItConstants.au3>
#include <Constants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

Const $APP = "c:\Apps\AES\aescrypt.exe"
;Prompt for password
Local $sPassword = InputBox("Password","Type password")
if not $sPassword Then Exit ConsoleWrite("Closed inputbox" & @CRLF)
$sPassword = StringStripWS($sPassword,$STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES)
Const $PARAMS = " -d -p " & $sPassword & " -o - "

;choose input file
Local $sFileOpenDialog = FileOpenDialog("Choose file", @ScriptDir, "AES (*.aes)", $FD_FILEMUSTEXIST)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "No file selected.")

Local $szDrive, $szDir, $szFName, $szExt
_PathSplit($sFileOpenDialog, $szDrive, $szDir, $szFName, $szExt)
Const $OUTPUTDIR = $szDrive & $szDir
Const $INPUTFILE = $szFName & $szExt
Local $WholeLine = StringFormat("%s %s %s", $APP, $PARAMS, $INPUTFILE)
FileChangeDir($OUTPUTDIR)

;run CLI app
Local $iPID = Run($WholeLine, $szDir, @SW_HIDE,$STDOUT_CHILD)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Install failed.")
Local $sOutput = StdoutRead($iPID)
If @error Then Exit ConsoleWrite("Error returned by StdOutRead! @error=" & @error & ", @extended=" & @extended & @CRLF)
While True
	$sOutput &= StdoutRead($iPID)
	If @error Then ExitLoop
	ConsoleWrite($sOutput & @CRLF)
WEnd

;Poor man's search: copy STDOUT into clipboard, launch Notepad, paste
ClipPut($sOutput)
$iPID = Run("notepad.exe")
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
WinWait("[TITLE:Untitled - Notepad2-mod; CLASS:Notepad2]")
Sleep(500)
Send("^v") ;paste
Sleep(500)
Send("^{HOME}") ;jump to first line in notepad
Post Reply