Jump to content

Newbie intermediate Q: Where to go from here?


Go to solution Solved by Mbee,

Recommended Posts

Okay, I've got a fair to middling handle on AutoIt v3 basics, but from here on the learning curve looks pretty foggy to me -- which is my problem of course, but still, I don't know what to read next and where to find it.  Somewhere between the language basics and a some basic functions and so forth, and on the other end, actually implementing my goals of having a few applications perform automated tasks in their GUIs, lies a gulf of ignorance waiting for me to get lost inside.  What lies in the middle?  Some currently unknown (to me) Windows API calls or what?  What's the operational programming map as well as learning map look like?

I'm a multi-decade, highly experienced systems programmer, but NONE of my work has been on PCs of any type or any PC operating system (I've done lots of embedded through high-end engineering computers instead).  I'm working on Windows XP and 7, but only as a user, not a programmer.  I don't know any Windows APIs whatsoever, and I don't particularly want to learn anything much more than is necessary to program AutoIt for manipulating a half-dozen apps.

To put a more practical EXAMPLE topic out there for those who prefer it such, in a current script, I'm going to activate an app, but first I want to know it it's already running.  I tried obtaining and looping through a WinList() looking for a Window title that matches my app's name, but it turned out that a folder with the same name was already open, so my primitive script confused a Windows Explorer folder window name with the desired application's name because they were identical.  What do I have to do to distinguish the two cases?  I figure there's some additional info I should be able to find using the Window handle(s) -- such as the name of the process which created it -- but I don't know where to find that kind of info on the documentation or learning map.  So I'd prefer a fuller reply than only a suggested solution to this particular practical question if possible.

Thanks for your patience folks!

Edited by Mbee
Link to comment
Share on other sites

Welcome to AutoIt and the forum!

As you already have basic AutoIt knowledge I think the next step is to automate your applications.

To check for a running application you can either use function "ProcessExist" to check if e.g. "application.exe" exists. Or if the application has a COM interface (like Word, Excel etc.) you could try ObjGet.

The next step on the learning curve is: Start coding. If you are unsure how to or run into errors, ask. We will be happy to assist.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Great to hear of you interest, and I'm sure you will find many in this community to help you, and the experience you bring may help us too.

The Help file for AutoIt and this Forum are it's greatest resources, outside of individual talented members.

Like anything you learn, it's an as you go learning process.

You will find plenty of info about Window's and their titles, classes, instances and how to get and apply handles, both here and in the Help file.

What you want to get out of AutoIt, ultimately depends on your end goal, but my advice is jump in and get dirty and then follow your instincts from there. As you seem to already know some basics, you really need to either do some of the harder tutorials available or determine a project that will give you a learning curve. If you are really serious about becoming a programmer though, you will need to do some reading from other general sources outside of AutoIt, to understand better the concepts involved.

In the end, this could take you away from AutoIt.

Is that what you want or do you just want to become better with AutoIt?

All knowledge can be helpful anyway.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

My Netbook had a little conniption, and so I missed what water said, but what he said too.

A personal note here may also help you.

A few things have helped me with my AutoIt learning.

(1) Having something I needed/wanted as a goal ..... that is particularly helpful.

(2) Following information in the Help file reference links.

(3) Regularly checking anything in the Examples section of the forum, that took my interest ... usually downloading code and comments for a rainy day ... of which there has been many. I've learnt much of what I know, from other people's scripts and careful experimentation.

(4) Not being afraid to challenge myself or ask what might seem like stupid questions. We all have dumb days and we were all newbies once.

(5) Be thorough with searching the Help file, and then the Forum, before asking for help. You gain an immeasurable amount by doing that.

(6) Making mistakes, but never (or rarely) giving up. Usually when I give up, it's only until I'm in a better position to deal with the difficulty or I realize there is a better way. I don't like conquering things just for the sake of it, unless I can see a real benefit for the time spent.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Oops, I just realized we should be doing all this in Chat ... which however, you won't see because of one post only.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Wow, the friendliness and kind willingness to help a newbie here is exemplary --  My thanks to water and especially warm thanks to TheSaint!

(I would have replied earlier, but I was expecting an email notification of replies....)

I've just completed successful development of my first personally-useful script, which is to activate or de-activate a specific clean-up task using R-tools R-Wipe&Clean (description here: http://download.cnet.com/R-Wipe-Clean/3000-2144_4-10159835.html)

Here's my source code (suggestions for improvement would be very much appreciated!):

#cs ----------------------------------------------------------------------------
    
    MyRWipeControl Version 1.0 - 11-Jun-2013
    AutoIt Version: 3.3.8.1
    Author:         Mbee
    
    Activate or De-Activate R-Wipe&Clean's Full Clean task
    
    If an R-wipe task is ready to run, the reg key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run will include the following:
    Subkey Value name: RWipeD  - Contents: C:\PROGRAM FILES\R-WIPE&CLEAN\RWIPED.EXE
    
    
#ce ----------------------------------------------------------------------------
#include <Array.au3>
#include <Constants.au3>
#include <Misc.au3>
#include <Process.au3>
#include <ProcessConstants.au3>
#include <String.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
#include <WinAPIError.au3>
#include <WindowsConstants.au3>


; Script Start - Add your code below here
Opt("MustDeclareVars", 1)
;
Const $Cmy_Max16bit = 65535, $Cmy_MaxWins = 256, $Cmy_MaxProcess = 256
Const $Cmy_RwipePath = "C:\Program Files\R-Wipe&Clean\RWipeRun.exe"
Const $Cmy_RwipeDPath = "C:\Program Files\R-Wipe&Clean\RWipeD.exe"
Const $Cmy_RWipeName = "R-Wipe&Clean"
Const $Cmy_RWipeProcName = "RWipeRun.exe"
;
Local $L_Stat, $L_RegString, $L_MBoxReturn, $L_ProcessID
Dim $L_RWipeWinTitleList[$Cmy_MaxWins], $L_RWipeWinHandleList[$Cmy_MaxWins]
Dim $L_ListOfProcs[$Cmy_MaxProcess][2]  ; ProcessList returns a 2-dimensional matrix
Local $L_CountOfProcs = 0, $L_RWipeProcCount = 0, $L_ThisStr = "", $L_RWipeWinHandle
Local $L_RWipeStatChange = "unchanged"
;
;
; --- Entry Point - Begin
;
AutoItSetOption("WinTitleMatchMode", 3)  ; 3 = Exact Title Match for window titles
AutoItSetOption("MouseCoordMode", 0)     ; 0 = Use coordinates relative to Window

;
; First we need to see if RWipe's got a current task run set, so we read the registry...
$L_Stat = 0
$L_RegString = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "RWipeD")
If $L_RegString == "" Then
    MsgBox($MB_OK, "Rwipe Reg Status", "Rwipe upon boot is INactive - Status = " & $L_Stat)
    $L_Stat = 0
Else
    MsgBox($MB_OK, "Rwipe Reg Status", "Rwipe upon boot is active - Key name = " & $L_RegString)
    $L_Stat = 1
EndIf
;
; Ask if the user wants to cancel or activate an Rwipe cleanup task
If $L_Stat = 1 Then
    $L_MBoxReturn = MsgBox($MB_YESNO, "Rwipe Status Change Request", "There's an RWipe task active -- Deactivate it?")
    If $L_MBoxReturn <> -1 Then
        If $L_MBoxReturn = 6 Then ; 6 means "Yes"
            $L_RWipeStatChange = "cancel"
        EndIf
    EndIf
Else
    $L_MBoxReturn = MsgBox($MB_YESNO, "Rwipe Status Change Request", "There's NO RWipe task active -- Activate it?")
    If $L_MBoxReturn <> -1 Then
        If $L_MBoxReturn = 6 Then ; 6 means "Yes"
            $L_RWipeStatChange = "activate"
        EndIf
    EndIf
EndIf
If $L_RWipeStatChange == "unchanged" Then
    Exit
EndIf
;
;    Since the user wants a status change, check to see if RWipe is already active
$L_ListOfProcs = ProcessList()
;;        $array[0][0] = Number of processes
;;        $array[n][0] = nth Process name
;;        $array[n][1] = nth Process ID (PID)
;;        The list can be empty if $array[0][0] = 0. No @error set in this case.
;;
$L_RWipeProcCount = 0
$L_CountOfProcs = $L_ListOfProcs[0][0]
If $L_CountOfProcs > 0 Then
    For $L_ctrA = 1 To $L_CountOfProcs
        $L_ThisStr = $L_ListOfProcs[$L_ctrA][0]
        If StringInStr($L_ThisStr, $Cmy_RWipeProcName) Then
            $L_RWipeProcCount += 1
        EndIf
    Next
EndIf
;
;    If Rwipe isn't active, make it so
$L_ProcessID = 0
If $L_RWipeProcCount = 0 Then
    $L_ProcessID = Run($Cmy_RwipePath)
    If $L_ProcessID = 0 Then
        MsgBox($MB_OK, "Rwipe Windows Activation Failure", "Rwipe Activation Error")
        Exit -1
    EndIf
    $L_Stat = WinWaitActive($Cmy_RWipeName)
    If $L_Stat = 0 Then
        MsgBox($MB_OK, "Rwipe Windows Activation Failure", "Rwipe Activation Error")
        Exit -1
    EndIf
EndIf
;
; If we've reached here, then the user wants to have R-Wipe change status, and it's active task, so do it.
;
; First, activate RWipe's main window
$L_RWipeWinHandle = WinActivate($Cmy_RWipeName)
If $L_RWipeWinHandle = 0 Then
    MsgBox($MB_OK, "Rwipe Tool Exiting", "RWipe Window Activation Failed")
    Exit
EndIf

;
; Now, resize window so that we know exactly where RWipe's non-standard controls are relative to the window
$L_Stat = WinMove($Cmy_RWipeName, "", Default, Default, 1040, 841)
Sleep(500)

; First click on "Full Task" button near top right of RWipe page to activate the window portion we need
$L_Stat = MouseClick("left", 897, 97)
Sleep(500)

; Then click on "Full Clean" row in Task List
$L_Stat = MouseClick("left", 480, 712)
Sleep(500)

; Now click the appropriate pseudo-button
If $L_RWipeStatChange == "cancel" Then
    $L_Stat = ControlClick($Cmy_RWipeName, "Deactivate Task", "[CLASS:Button; INSTANCE:144]")
Else
    $L_Stat = ControlClick($Cmy_RWipeName, "Activate Task", "[CLASS:Button; INSTANCE:143]")
EndIf
Sleep(800)
;;;---------------

MsgBox($MB_OK, "Rwipe Tool Exiting", "RWipe Tool - Exiting")
Exit 0

R-Wipe & Clean often doesn't use standard controls (if I'm interpreting AutoIt's Info tool results properly, which I very well may NOT be), and so to get the GUI into the correct mode for the ControlClick function I was finally forced (after much trial & error!) to click the mouse in a couple of places before selecting the relatively few standard controls R-Wipe does provide.

ALSO, I have a major question: Since the relative coordinates for the mouse clicks I need can easily change based on whether or not the user stretched or shrunk the main window, I could think of no solution other than to force the window (with WinMove) to be a precise width and height. Otherwise the clicks could end up at the wrong place.  How do others solve this problem?

Another question is whether or not I shoud be completely scrupulous about checking the return status from various operations.  For example, I ignore the ControlClick calls' return status in the code above, but in other cases I do check the return status and exit upon failure.  This feels very arbitrary, and being arbitrary feels, well, wrong to me (I'm usually quite a stickler for such details...)  Should I lighten up or darken down on this?

I'm eager for feedback, so critique away!

Thanks again, all!

Link to comment
Share on other sites

Oops, I just realized we should be doing all this in Chat ... which however, you won't see because of one post only.

 

Hi, TheSaint!  Sorry if this is another dumb newbie question that I could answer by reading a bunch of FAQs, but why should we be using Chat?  What's that about?

Thanks again for your very kind assistance!

Link to comment
Share on other sites

but why should we be using Chat?  What's that about?

 

When the conversation started, it was just a discussion of "what can I use AutoIt for?" which is something that would be better suited for the Chat forum instead of General Help and Support.  Now that there's actual code involved, it fits beautifully into its current location.

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Link to comment
Share on other sites

 

ALSO, I have a major question: Since the relative coordinates for the mouse clicks I need can easily change based on whether or not the user stretched or shrunk the main window, I could think of no solution other than to force the window (with WinMove) to be a precise width and height. Otherwise the clicks could end up at the wrong place.  How do others solve this problem?

 

This is usually solved using ControlClick. Check http://www.autoitscript.com/autoit3/docs/functions/ControlClick.htm for how to use it. You can get the controlID using au3info in Scite's Tools menu. Hope that helps.

Link to comment
Share on other sites

Another question is whether or not I shoud be completely scrupulous about checking the return status from various operations.  For example, I ignore the ControlClick calls' return status in the code above, but in other cases I do check the return status and exit upon failure.  This feels very arbitrary, and being arbitrary feels, well, wrong to me (I'm usually quite a stickler for such details...)  Should I lighten up or darken down on this?

Error checking is never a bad thing. At least I would always do some kind of error checking if a statement relies on the successful execution of a prior statement and the script would crash if an error goes unnoticed.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 3 weeks later...
  • Solution

Sorry for the delay in responding.  Life gets complicated, as you all know all too well...

I just wanted to thank all the respondents for their kind and helpful comments!

This is a great place, with great folks!

 

Take care...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...