Look into the Windows Scripting Host and check MSDN regarding system hooks.