Help getting started in autoit

Hi,
I was told autoit will be much better then bat files to help do some cleaning up after our software installation.
The black batch script box is very unprofessional, and sometimes people close it before it can finish processing.
We're under a very tight dedline, far behind schedule. I'm struggling a bit getting used to the new syntax.
I'm posting the bat text here, if anyone can please help give some examples of how autoit handles the functions we're using so we can get the new script tied down as soon as possible, we'd really appreciate the help.
Thanks
Steven.

@echo off
TITLE Backup Albums
if exist C:\RapidStudio_Albums MOVE /Y C:\RapidStudio_Albums %temp%
TITLE Copy Shortcuts
if not exist "C:\Program Files\RapidStudio_Support" MKDIR "C:\Program Files\RapidStudio_Support"
xcopy QSApp.ico "C:\Program Files\RapidStudio_Support" /Y
xcopy RapidStudio_QuickSupport.exe "C:\Program Files\RapidStudio_Support" /Y
xcopy RapidStudio_QuickSupport.exe %userprofile%\desktop /Y
echo [InternetShortcut] >"%userprofile%\desktop\RapidStudio Web.url"
echo URL=http://www.testing.rapidstudio.co.za/ >>"%userprofile%\desktop\RapidStudio Web.url"
echo IconFile=C:\Windows\System32\url.dll >>"%userprofile%\desktop\RapidStudio Web.url"
echo IconIndex=0 >>"%userprofile%\desktop\RapidStudio Web.url"
echo.
echo.
TITLE Wait for Setup.exe
:CHECK_PROCESS
set found=N
for /f "tokens=*" %%a in ('tasklist ^| findstr /i "Setup.exe"') do set found=Y
rem echo Process=Setup.exe
rem echo found =%found%
> wait.bat echo ^@CHOICE ^/T %%1%% ^> NUL ^/D y
call wait.bat 5
del wait.bat
if "%found%"=="Y" echo Process is still running...
if "%found%"=="Y" GOTO :CHECK_PROCESS
echo Process has stopped
TITLE Change attributes
attrib -R "C:\Program Files\RapidStudio\MPR500 Pro 5\*.*"
DEL /S /Q /F /A:S "C:\Program Files\RapidStudio\MPR500 Pro 5\thumbs.db"
DEL /S /Q /F "C:\Program Files\RapidStudio\MPR500 Pro 5\thumbs.db"
exit
StevenHookAsked:
Who is Participating?
 
gimosubyConnect With a Mentor Commented:
Yeah, you could do a registry read like this: $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\RapidStudio", "installDir")

Exact registry path depends on how RapidStudio would write to registry of course.
0
 
Bryan ButlerCommented:
Autoit it for GUI testing automation.  It would not make sense to use it for anything else really.  Definitely not this type of thing.  Powershell would be the best thing to use, but it's only installed by default on win7.
0
 
gimosubyCommented:
I suggest using AutoIT, it works awesome, I'm a network admin and I use it everyday. I've converted your bat code to AutoIT
; Backup Albums

If FileExists ( "C:\RapidStudio_Albums" ) Then FileMove ( "C:\RapidStudio_Albums", @TempDir , 1 )

; Copy Shortcuts

If Not FileExists ( "C:\Program Files\RapidStudio_Support" ) Then DirCreate ( "C:\Program Files\RapidStudio_Support" )
FileCopy ( "QSApp.ico", "C:\Program Files\RapidStudio_Support" , 1 )
FileCopy ( "RapidStudio_QuickSupport.exe", "C:\Program Files\RapidStudio_Support" , 1 )
FileCopy ( "RapidStudio_QuickSupport.exe", @DesktopDir , 1 )
FileCopy ( "source", "dest" , 1 )
FileCopy ( "source", "dest" , 1 )

$file = FileOpen(@DesktopDir & "\RapidStudio Web.url", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, "[InternetShortcut]" & @CRLF)
FileWrite($file, "URL=http://www.testing.rapidstudio.co.za/" & @CRLF)
FileWrite($file, "IconFile=C:\Windows\System32\url.dll" & @CRLF)
FileWrite($file, "IconIndex=0")

FileClose($file)

ProcessWaitClose ( "Setup.exe" )

FileSetAttrib ( "C:\Program Files\RapidStudio\MPR500 Pro 5\*.*", "+R" )

FileDelete ( "C:\Program Files\RapidStudio\MPR500 Pro 5\thumbs.db")

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
StevenHookAuthor Commented:
Thanks so much.
Is is possible to detect where the software is installed id they customise the installation path?
Perhaps from the registry?
Regards
Steven
0
 
Bryan ButlerConnect With a Mentor Commented:
Very nice gimosuby!  I stand corrected.  I guess they are just wrappers for the most part, so it should work fine too.  I have really only used it for GUI tests and forgot about all the functions autoit has.  Thanks for the code too!
0
 
gimosubyConnect With a Mentor Commented:
You're welcome. You can do amazing things with AutoIT, I have it do a lot of stuff at my company and the help file is very thorough. Glad I could help.
0
 
StevenHookAuthor Commented:
Hi.
Another glitch....
The section that deleted the thumbs.db isn't working.
I think it might be because the files are hidden? or "system files"?
Is there a way around this?
Thanks
Steven
0
 
gimosubyConnect With a Mentor Commented:
Strange, I was able to delete a thumbs.db file just fine with filedelete()
You can try this:

FileSetAttrib("C:\Program Files\RapidStudio\MPR500 Pro 5\thumbs.db" ,"-RHS")

to clear its read-only, system, or hidden file status.

Alternatively you could run your own batch file lines in a hidden command prompt window like this:

Run(@ComSpec & " /c " & 'DEL /S /Q /F /A:S "C:\Program Files\RapidStudio\MPR500 Pro 5\thumbs.db"', "", @SW_HIDE)
Run(@ComSpec & " /c " & 'DEL /S /Q /F "C:\Program Files\RapidStudio\MPR500 Pro 5\thumbs.db"', "", @SW_HIDE)
0
 
StevenHookAuthor Commented:
Awesome - Thanks.
Will stick to auto it with the -RHS
Steven
0
 
StevenHookAuthor Commented:
Ok, Last one I think.
how can I delete files that match a criteria recursively?
I want to delete all the thumbs.db in the whole program folder and all sub folders?
Tx.
Steven.
0
 
gimosubyConnect With a Mentor Commented:
This should do the trick:
Dim $FolderName = "C:\Program Files\RapidStudio"

ScanFolder($FolderName)

Func ScanFolder($SourceFolder)
	Local $Search
	Local $File
	Local $FileAttributes
	Local $FullFilePath

	$Search = FileFindFirstFile($SourceFolder & "\*.*")

	While 1
		If $Search = -1 Then
			ExitLoop
		EndIf

		$File = FileFindNextFile($Search)
		If @error Then ExitLoop

		$FullFilePath = $SourceFolder & "\" & $File
		$FileAttributes = FileGetAttrib($FullFilePath)
		if $File = "thumbs.db" then FileDelete($FullFilePath)

		If StringInStr($FileAttributes,"D") Then ScanFolder($FullFilePath) ;Resursive

	WEnd

	FileClose($Search)
EndFunc

Open in new window

0
 
Bryan ButlerCommented:
Thanks for the points as gimosuby was awesome here.  The recursion is very nice!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.