How to kill a vbscript running the sendkeys command

It is nearly impossible to stop a wild VBScript running amuck with the sendkeys command on windows. To be sure you can always attempt to open windows taskbar and try to kill the process, if you know its name and if the script gives you enough time to open the taskbar and kill it. But in my experience its impossible to do that without creating a whole mess with sendkeys and sometimes, the only way out is to quickly open or switch to a text editor and wait patiently until it ends.

Scripts that I run frequently, I usually put them in my Quick launch bar so I can kick them off without having to switch windows. The AppActivate() command activates the right window for the script to work on. AppActivate unfortunately doesn’t restore windows if they are minimized. You might have realised this the hard way, as did I, when minimizing all windows and trying to trigger the script from the desktop.

Since VBScript doesn’t provide it’s own way to kill runaway sendkeys commands, it’s up to us to stop it. Every script that I write looks for a file called ‘stopscript.txt’ on the desktop, once every few times the sendkeys is called. If the file exists, it stops and no more sendkeying after that. To create that file, I’ve written another script whose only job is to create an empty file called ‘stopscript.txt’ on the desktop if it doesn’t exist. This script is also placed in my quick launch so it can be started quite easily. So whenever a sendkeys script starts behaving weird, I just start this script and the other one terminates instantly. I’ve found this technique to be a lifesaver in many situations. However, it does require that you be careful and call the file checking function at the right places when developing your script.

Also, always have an empty notepad window open when working with sendkeys. If it goes amuck, you can capture most of the bad commands by bringing the notepad window into focus. This is just another precaution :). Also, you can have your main script delete the stopscript.txt file at the very beginning so that you don’t have to manually switch to the desktop and delete it yourself. To stop it again, click on the stopping script.

VBScript is by no means a great solution for sendkeys automation. There are several professional tools available which can achieve the same. But VBScript comes for free on a windows machine. And when working with clients, sometimes you’re not allowed to install anything on the system and that’s when VBScript comes in handy as the poor man’s automation tool!


Checking if a file exists and creating it in VBScript

Laptop screen brightness controls missing – Acer 5742G, Windows 7 – Teamviewer culprit

Recently the brightness controls disappeared from my Windows 7 installation and I had absolutely no idea why. I reinstalled nvidia and intel drivers (I have optimus) and it still didn’t work. Finally, after searching around, I found this post which said that the problem appeared to be because of TeamViewer. I uninstalled it and voila! The fn+Right and Fn+Left keys are working again. Thank goodness, it was getting a bit too painful.