Saturday 8 February 2014

Do you know how simple is programming? Try it yourself. AutoIT

You don't need to be IT expert to write a program, you can write your own programs with this script language:

 

AutoIT



There are a lot of complicated programming languages​​, but there are also simple language that everyone can use, one of them is AutoIT script language.

He is very simple and easy to learn. You can write simple and complicated programs for whatever you need.

How to start with AutoIT? You need to do 1. and 3. step on this link. After that you are ready to write your own programs.

I will show you how to make program to open your CD drive and close it in a loop every 1 minute. :D
We all wanted in some point to be a hackers, this is a closest you can be a hacker without knowing anything about programing.

So how to start? You can do like this, go to your desktop or folder you want to make programs and click right click, from menu select "New" then select AutoIT script. Name it like "CD Drive" or something like that. After you name it, you need to right click on it and click on Edit Script, by default if you just open it i will run script and nothing will be executed because you don't have any code on script.

So we click on Edit Script and now you see Script Editor, all you need to do now is to write your code and use your imagination. :)
We are building CD script, so what do we need? Script gonna be in a loop because we want that CD open's every 1 minute. So how to make a loop?

You can do a loop very easy and intuitive like this:
While 1=1

Wait! What? :D Yes this is a loop, if you think about it loop will do code while condition is correct, in our example 1 is always equal to 1 so our loop will do this always! :)

So how will the loop know where is the end of our code? We need to add this:
WEnd

W - represents while loop and End - end of the loop so every simple for now. :D

Hmm we want to do this loop every 60 second so we need to pause or "sleep" our program for 1 minute, how we gonna do that? Just add this:    sleep(time in millisecond)
So we need to our program sleeps for 60 second, 1 second has 1000 millisecond so we just add sleep method:
while 1=1

sleep(60000)
WEnd

We have our loop who will execute code in every minute in just 3 line of code's :D How cool is that? :)
Now we need to open a CD drive, you can say hmm that is hard, hmm no! Programing is simple because all you need to do is to call method who will do something that we need, so we need method to get CD Drive.

$var = DriveGetDrive( "CDROM" ) 

In this variable called "$var" we get all CD drives on computer, if you think what is this "$" sign means, that is AutoIT thing to say what is variable, you don't need to know anything about that...

So we have all drives in one variable, now we need to open it, so we need to iterate through all cd drive's and open it. We will do it like this:
If not @error Then
For $i = 1 to $var[0]
    CDTray($var[$i] , "open")
Next
EndIf

We first ask is there some kind of error in calling CD Drive's? If not we use for loop to iterate through all CD drives, so if we have 3 drives, with for we go from 1 to 3, we now use 1drive call method to open it: CDTray($var[$i] , "open")When we are finished with first drive we call method Next it will give us next drive, so for loop will now do same thing with second drive, after second is finished we call Next and call it for third drive. So with that 5 lines of codes we open all CD drives on computer. Our code look like this now:

While 1=1

$var = DriveGetDrive( "CDROM" )
If not @error Then
For $i = 1 to $var[0]
    CDTray($var[$i] , "open")
Next
EndIf

sleep(60000)
WEnd

And we finish it :D If you want to close it and after a few second you can use that same code but change "open" to "close" for operation and add sleep between open and close about 20-30 second and you are good. :D

Now we need to create executive program that we can send someone to make a joke with him. :)
In Script Editor menu you have Tools tab, open it and click "Build". That will call AutoIT function to make our program become executive or .exe file. If you don't have any mistakes with your code in your folder or desktop where did you create this script will be file NameOfTheScript.exe and all you need to do now is to zip it or rar it and send it to someone you want to go insane. :P

You can run it on your computer as well, if you want to stop it just use Ctrl+Alt+Delete and kill the program... :) 

This is a tutorial how to make CD Room open's with 10 lines of code and you don't need to be programer to do that. 
If you want to learn more try to read AutoIT documentation or just leave comment bellow and we will make new tutorial how to do similar crazy stuff with AutoIT... :)

If you like this post please like us on Facebook, subscribe, share it, do whatever you want with it... :)
Have a good one. M.L.


No comments:

Post a Comment