Windows Scripting With AutoHotKey (AHK)
I am not so sure this topic would deserve and entire tutorial, but I find it very useful in my day to day activities. I am sure, like me most of you have to do repetitive tasks in windows daily. If we were in a *nix environment writing a quick script can save you tons of time, why not do the same inside of windows? Well a few years ago while i was working support for a fortune 500 company one of the other techs introduced me to AutoHotKey (referred to as AHK from here on out) to automate some tasks we found ourselves preforming often. So I am going to pass this information on to SX crew in hopes that we can make a script that automates tasks we find useful in the scope of computer security.
First off you guys may want to check out http://www.autohotkey.com/docs/ for a full explanation of this scripting language, they have lots of
tuts and some nice code examples to get you started. Below I will throw out some of the lines from my automation script, and explain them the best I an.
The first feature we will cover is hotstrings. Hotstrings are used to expand abbreviations as you enter them. So the first line in my script takes an abbreviation you type, in this case [em, which when entered will display my actual e-mail address, the example:
::[em::forsaken@mywebhost.com
This is a very basic concept that we will expand on, using the hotstring feature we can greatly reduce the time it takes to respond to forum posts and emails, as the following works wonders:
::[osri::
(
The customers windows install has proven to be corrupted or infected by a virus or malware, after discussing the options to the customer they agreed
to preform a reinstall of windows. The OSRI was preformed and the system drivers and software has also been reinstalled. Customer is satisfied with
the results and the case is now closed.
)
After a few days of creating these hotstrings, I greatly decreased the time it takes for me to enter case information into our documentation system. Even when doing some c++ developing inside windows this can be used to eliminate typos and decrease the time it takes to develop on any project an example of this would be:
::[while::
(
while ()
{
}
)
Obviously this can be expanded to Handel specific code blocks that you use often, hotstrings are only limited in function by your imagination.
HotKeys
Hotkeys can be used to easily trigger an action (such as launching a program or sending text to the crusor). In the following example, the hotkey Alt+s is configured to open soldierx.com in your default web browser. The exclamation sign [!] stands for the alt key, for a full list of modifier symbols check out http://www.autohotkey.com/docs/Hotkeys.htm
!s::
Run http://www.soldierx.com
return
In the final line above, "return" serves to finish the hotkey. In the next example we will assign a hotkey to send keystrokes to the active window by using the send command:
!t::
Send Thanks for your time,{enter}(tab)Forsaken
return
Again this is only a functional example, scripting will become truly powerful after you personalize it to your specific needs. But creating hotkeys and hotstrings doesn't cover half of what AHK is capable of doing. It has support for creating GUI to gather or display information to the user. When you combine all of these functions you will realize that this language has alot to offer in the terms of automation. This post will be updated to show some examples of the more advanced functions of AHK. Now this is were I offer an open challenge to the SX community, what hotkeys or hotstrings would you use on a regular basis? The point here is develop a script to automate the most common tasks preformed by the SX crew. So please post a response to this topic if you find this short paper useful, or if you have any questions or want to request a function for the SX AHK script.