1. Hey Guest Did you know you can win an Honor 10 phone worth ₹33,000 and an additional ₹70,000 in paytm vouchers, just by replying to some threads and taking part in the discussions happening in the Honor Hub?

    What are you waiting for? Start commenting and start winning! Remember to read the instructions posted here.

    Dismiss Notice

Automating WinXP!!!(yeah!)

Discussion in 'Tutorials' started by blackleopard92, May 8, 2006.

Thread Status:
Not open for further replies.
  1. blackleopard92

    blackleopard92 New Member

    Joined:
    Sep 4, 2004
    Messages:
    310
    Likes Received:
    0
    Trophy Points:
    0
    This is my first tutorial for something.Many people ask me about automating hundred of windows task effeciently.

    And making tutorials IS hardwork!!!Now I understand what all those copyright thingies mean.And they apply here too!

    (Programming!!!. Yeah loads of programming on this page, that too to control the ugly brat we have to put up everyday i.e Windows!!!)

    Although I love programming, but I don’t think many share that feeling, however If u can’t make head or tale of the below text, but want something done, post here.All those who did understand would definately help u and get reps in return !!)



    Auomating windows gives a high, after all there’s no felling better than controlling this brat/hell of software, and for a change making things EASY for u!

    Windows ships with 2 basic tools to automate itself, i.e. batch files and Scheduled Tasks.
    However, they are hardly are something u would mess with, batch files are cumbersome, based on DOS commands.while scheduler is hardly what we call automation system

    Two types of 3rd party programs come into this fray, the are
    1.Macro based automation
    2.Script based automation

    Macro based automation are easy, are simple to set up.
    However they hog memory, and system resources.So hardcore users like me(programmers, gamers) hardly like them

    Script based automation soln are opposite of macros.They are programming languages made specially for system automation.However they “do not” hog resources, and people like me love them.They can be compiled into executables, can be highly customized for your needs and most important fact is that they give me a feeling of control over this brat that macro can’t achieve ever!!!

    And the best thing about them are FREE

    I had been searching for a simple script based Script based automation system for daily useage.And I came across autoit.


    Autoit is a Script based automation and totally free.Its easy to understand .
    .
    http://www.autoitscript.com/autoit3/

    download and install the 3Mb program.

    There are some sample scripts which u should read and run to get the feel and power of the program.

    They package comes with small set of tutorials which explain the functions.
    Their help file is simply superb and well written.

    However, I always believed that real use of something can only be found when it is used effectively.And hence I came up with this program/script for demonstration.

    I had just downloaded it to automate the process of opening multiple programs
    (around six) which I always open before going on to net.

    I will study this scripting language more and write a more comprenhsive tutorial when I get time.

    Part 1:Starting from somewhere


    Here, I plan to open 6 program with one click.here's the list of them
    1.Mozilla
    2.MSN Messenger
    3.Yahoo! Messenger
    4.Windows Media Player
    5.Evil Lyrics (lyrics on fly, i.e. play a song and lyrics are auto displayed. link
    6.Flashget

    Imagine u clicking all the above everytime u go online!!

    now, make a new .txt file, eg all_in_one.txt
    ( right click on desktop-> new->text document.rename it)
    you can also directly make the script, by
    right click on desktop-> new->New AutoIt v3 Scrip.rename it

    now open it up,(or if you made the script, rt click and select edit script) and notepad should start.

    write/copy lines written below.


    Run("C:\Program Files\Windows Media Player\wmplayer.exe prefetch:1")
    Run("C:\Program Files\mozilla.org\Mozilla\mozilla.exe")
    Run("C:\Program Files\MSN Messenger\msnmsgr.exe")
    Run("C:\Program Files\Yahoo!\Messenger\YPager.exe")
    Run("C:\Program Files\Google\Gmail Notifier\gnotify.exe")
    Run("C:\Program Files\EvilLyrics\EvilLyrics.exe")
    Run("C:\Program Files\FlashGet\flashget.exe")


    (If u do not use any of the above listed programs, simply delete/replace the associated line)
    Also note that, like all programming languages, its case sensititve!)


    Also, I assume that you have the associated prog installed at default places.If not, then just rt click at their short cuts and copy the "target" box text into the parenthesis.

    here's a pic:
    (the wallpaper was created by me in blender .My first try in making something in Blender )
    I can tell you, there's nothing more satisfying than seeing your hardwork(even of poor quality)

    [​IMG]


    after you have done all of the above, rename the extension the .txt to .au3, ie all_in_one.txt to all_in_one.au3.
    However, no need to do this if you created script file directly.

    now run the script! Voila! everything runs on a single double click.

    Now let's see what we have done:
    the run function:

    syntax.

    Run ( "filename" [, "workingdir" [, flag]] )

    filename: The full name of the executable (EXE, BAT, COM, or PIF) to run.
    workingdir: [optional] The working directory.
    flag: [optional] The "show" flag of the executed program:
    @SW_HIDE = Hidden window
    @SW_MINIMIZE = Minimized window
    @SW_MAXIMIZE = Maximized window

    Now our command:Run("C:\Program Files\mozilla.org\Mozilla\mozilla.exe")
    i.e. we simply told the WinXP to run the specified application(in this case mozilla).
    Since we did not supply any working dir and any additional options, they previous settings (when app was previously opened) were used.

    Now, lets see how we can improve our nifty script.



    ===============================================================================
    ===============================================================================




    Part 2:Message box


    I think we should add a dialog box so that accident clicking can be avoided.

    Lets add the below code to starting of file:
    (rt click file ->edit script, and don’t ask me again )


    ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
    $answer = MsgBox(4, "all in one", "are u sure?")


    ; Check the user's answer to the prompt (see the help file for MsgBox return values)
    ; If "No" was clicked (7) then exit the script
    If $answer = 7 Then
    MsgBox(0, "all in one", "OK. Bye slippery fingers!!!")
    Exit
    EndIf


    Wow! What happened? Reminds me of C++ if_else conditional statement, its actually that

    Lets look again.
    The ‘;’ operator is used to tell the WinXP that ignore the lines that have been added after it.

    MsgBox function
    Syntax:

    MsgBox ( flag, "title", "text" [, timeout] )
    Parameters

    flag The flag indicates the type of message box and the possible button
    combinations of buttons to display.See help file for list.
    title
    The title of the message box.
    text The text of the message box.
    timeout [optional] Timeout in seconds. After the timeout has elapsed
    the message box will be automatically closed.



    $answer = MsgBox(4, "all in one", "are u sure?")

    By comparing we can see that we told the complier to open a window with 2 buttons OK and Cancel, name the window as all in one and display text are u sure?

    Its return value is a integer which we stored in the variable $answer which we use to compare in if condition.
    The return value allows us to know which button has been pressed.

    You don’t need to declare(make) variables when u use it in the above way.
    However if u want to, read help.(No use in making this more difficult)

    Moving to later part of script,

    If $answer = 7 Then
    MsgBox(0, "all in one", "OK. Bye slippery fingers!!!")
    Exit
    EndIf


    Here, we are comparing the value of $answer variable.
    If the value is 7, then show another MsgBoxm, and exit the program using Exit command.
    Since all good things have to end somewhere, we secipy EndIf to close If conditional statement.

    That’s it.Now we have what we calls as basic ‘slippery fingers effect’ handler

    The below windows will show what is the result of above .

    [​IMG]

    [​IMG]

    Let’s improve further.



    ==========================================================
    =========================================================



    PART 3:Sending messages.

    The above one was diff, wasn’t it
    Hence I will write a simple one.

    Now lets review our script.There’s one flaw as I see it.
    It doesn’t make WMP play music!!!

    But we fix that now.

    Look at the below script.


    Run("C:\Program Files\Windows Media Player\wmplayer.exe prefetch:1")

    ;new code!
    WinWaitActive("Windows Media Player")
    Send("^p")

    Run("C:\Program Files\mozilla.org\Mozilla\mozilla.exe")
    Run("C:\Program Files\MSN Messenger\msnmsgr.exe")
    Run("C:\Program Files\Yahoo!\Messenger\YPager.exe")
    Run("C:\Program Files\Google\Gmail Notifier\gnotify.exe")
    Run("C:\Program Files\EvilLyrics\EvilLyrics.exe")
    Run("C:\Program Files\FlashGet\flashget.exe")


    Two lines for auto music :happy
    But why this is in third part?Because Luke, those lines hide more than u see.


    The WinWait function:
    Syntax:

    WinWaitActive ( "title", ["text"], [timeout] )
    title The title of the window to check.
    text [optional] The text of the window to check.
    timeout [optional] Timeout in seconds


    This command tells WinXP to wait till the window with “title” having “text” is active, then continue running the script.
    Note the window has to be active

    The Send func:

    Send ( "keys" [, flag] )

    Syntax:

    keys The sequence of keys to send.
    flag [optional] Changes how "keys" is processed:
    flag = 0 (default), Text contains special characters like + and ! to indicate SHIFT and ALT key presses.
    flag = 1, keys are sent raw.

    Now our command chain:
    WinWaitActive("Windows Media Player")
    Send("^p")


    Here we tell WinXP to wait till a active window with title “Windows media player” and any text opens up.And then send CTRL + P to it.(shortcut to play music)

    Now did I hear “Wait leo, how did u know about the title of WMP ?”
    Good ques, and the reason its 3rd part.

    AutoIt comes with a simple tool the AutoIt info Window.It gives info about the current window.
    Take a look at following screenshots:

    Here, I have opened WMP for the first time:

    U can see The Info view showing title and text, however once the song plays, the title changes:

    The title has changed to display current song, playlist with app name.Keep This thing in mind, when u try to automate windows.

    The fourth Part is Quite diif to understand and I urge u to go through this script help file and make some yourself.

    Try this, automate Wimamp to automatically play songs when opened,and then mimimise winamp.
    The first one to make the most sturdy one will get reps from me!.

    =================================================
    =================================================

    Part 4: Options and check boxes.

    I am writing it now, however I have to conduct some experiments before I am sure about what I am doing.

    You ask What its about?
    Suppose you are in no mood to listen to music, but want to run all the rest.
    Well u might say, “make another script, easy leo :)”.Yeah, nice one stop soln, however if I don’t want to run another program?Another script?That will result in 720 various scripts!!!

    Now there must be a simple way..., should be in the help file........ ,hmmm..... what could it be ..... , maybe check boxes.......Ah here it is!
    Will write about it in a moment, when I figure about it myself )

    You see, need breeds desire, desire to create to simplify life.You will also find many more examples in your XP experience which could be simplified.
    Find them and ask us, we are always there for help.After all we are the community.
     
    Last edited: May 9, 2006
  2. Vishal Gupta

    Vishal Gupta Microsoft MVP

    Joined:
    Jul 28, 2005
    Messages:
    5,173
    Likes Received:
    121
    Trophy Points:
    0
    Location:
    AskVG.com
    a loooooooooong and nice tutorial :)
     
  3. dIgItaL_BrAt

    dIgItaL_BrAt New Member

    Joined:
    Jan 23, 2005
    Messages:
    1,135
    Likes Received:
    2
    Trophy Points:
    0
    great tutorial,dude!
    .
     
  4. adit_sen

    adit_sen New Member

    Joined:
    Feb 8, 2004
    Messages:
    342
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Perth, A*stralia
    gr8 tutorial....well done...

    peace...
    aditya
     
  5. OP
    OP
    blackleopard92

    blackleopard92 New Member

    Joined:
    Sep 4, 2004
    Messages:
    310
    Likes Received:
    0
    Trophy Points:
    0
    how did u know my name!!!!!!!!!:p

    Adit_sen??
     
  6. kin.vachhani

    kin.vachhani Dreaming Future

    Joined:
    May 29, 2005
    Messages:
    177
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    \internet\home
    nice one man keep it up
     
  7. The CyberShot

    The CyberShot New Member

    Joined:
    Jul 24, 2006
    Messages:
    45
    Likes Received:
    6
    Trophy Points:
    0
    Re: Automating WinXP!!!

    Great Work. Simply Great.

    CyberShot
     
  8. arunks

    arunks Hey here is the aks

    Joined:
    Jan 7, 2006
    Messages:
    809
    Likes Received:
    5
    Trophy Points:
    0
    Location:
    punjab
    good..but whta harm in manual
     
  9. Sparsh007

    Sparsh007 Formerly Spashy

    Joined:
    Dec 1, 2005
    Messages:
    250
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Pluto
    cool Tutorial
     
  10. Ishan

    Ishan New Member

    Joined:
    Jun 12, 2005
    Messages:
    366
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bharuch,Gujarat,India
    You are great "Black leopard92"..u r gr8 atleast for me!
     
Thread Status:
Not open for further replies.

Share This Page