Automating WinXP!!!(yeah!)

Status
Not open for further replies.

blackleopard92

In the zone
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 .
.
*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)

*img367.imageshack.us/img367/2526/partb20na.jpg


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 .

*img58.imageshack.us/img58/2954/boxone2cw.jpg

*img79.imageshack.us/img79/7642/box2cut2tq.jpg

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:
Status
Not open for further replies.
Top Bottom