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
---
Edit: Save output to temp file to avoid wrong accented chars when copying CLI output to clipboard

Code: Select all

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

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Const $APP = "C:\Program Files\AESCrypt\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)

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

; Generate a unique filename in the @HomeDrive directory and starting with the "prefix" labelled prefix_
Local $sTempFile = _TempFile(@WorkingDir & "\")

;save CLI output to temp file instead of STDOUT to avoid cp1252/utf-8 garbage
Const $PARAMS = " -d -p " & $sPassword & " -o " & $sTempFile

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", "Running 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
WEnd

$sOutput = FileRead($sTempFile)
FileDelete ($sTempFile)

;Poor man's search: copy output 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
Local $hHdl = WinWait("[TITLE:Untitled - Notepad2; CLASS:Notepad2]","",10)
if  not $hHdl then Exit MsgBox($MB_ICONERROR,"Error","Windows not found")
Sleep(500)
Send("^v") ;paste
Sleep(1000)
Send("^{HOME}") ;jump to first line in notepad
Post Reply