25 Aug 2009

Batch Programming to Rescue


Few months ago, our Sony VAIO failed to work in par with all other normal VAIOs. It booted in snail’s pace, the fonts in the desktop became arguably large and our internet surfing was attacked by numerous e-bombs. Not to mention that our full version NAV was up and running healthy amidst all these havoc with scan messages showing “Total security risks detected 0”. Using the luxury of internet browsing at work place, my hubby produced a series of instructions, to be carried out by me, at home on our VAIO. The primary mission was to download and run Dr. Web CureIt Anti-Virus. Dr. Web CureIt is a standalone anti-virus and anti-spyware scanner that scans your PC for viruses, trojans, adware, spyware, hack tools, rootkits, and other malware.

Waging war with e-bombs I somehow managed to download Dr. Web (not full version though), installed and executed the application in safe mode. To my surprise, it trapped and quarantined circa 236 viruses from my C: drive alone. I had no clue, whatsoever; NAV was accomplishing running on my PC all this time.


Some of the .exe files transporting the viruses were self-downloaded applications from web. On quarantining those .exe files and making some registry corrections, the occurrence of e-bombs considerably reduced and was able to bring our laptop in a working state.

However on triggering Dr. Web scanning after a weeks’ time, it spotted self-downloaded .exe files again in temp directory. This repeated occurrence of the malicious programs made me sincerely think of taking proactive measures in protecting my system using some custom utility. The primary target of my utility was to delete .exe and .tmp files dropped in temp directories, as soon as the system is booted and carry out the deletion task at regular intervals.

AUTOEXEC.BAT; this was the first file that flashed in my memory for the above solution. This is a plain-text batch file and as the name stands its function is to automatically execute commands in the file, on system startup. I vaguely remember, coming across this concept, in my Advanced Diploma in Systems Management, at NIIT in 1992. Those were the days I learnt about DOS and batch programming wondering each and every day, where the hell these would be of any use to humanbeings in real world. In my day to day routine, of catching bus to college at 7:30 am, starting my day with Numerical Analysis at 9:30 am, and ending with Abstract Algebra at 3:30 pm, I totally failed to understand the significance of batch programming. Because of the lack of basic computer education at school level, for the first one year of my diploma, I was clueless for why and what, I was learning about DOS and Batches.

After 17 years, sailing through Masters Degree in Computer Applications, getting into programming and testing Microsoft Technologies and Java applications, I set to discover the real power of batch programming. To my disappointment, AUTOEXEC.BAT had become obsolete with the XP world. However, to our advantage, any .bat file placed in startup folder of ones profile, can behave like an AUTOEXEC.BAT and as a bonus we can have multiple .bat files placed in the folder. On brushing through my rusty knowledge in batches, I developed the following few lines, to protect my system from simple version of viruses. After implementation of the below .bat file, my VAIO runs with all serene to my satisfaction. Occasionally, I do encounter messages stating “Unable to delete .exe file”. In such instance, I turn off my internet connection and kill the mentioned .exe process; otherwise I would simply restart my PC.

The following program starts MS Outlook based on user input, deletes .tmp and .exe files every 30 minutes from windows/temp directory and profiles temp directory and displays the approximate time of when the files picked for deletion.

Echo "Starting batch"
Echo off
set /P INPUT=DO YOU WANNA INVOKE REMINDERS FROM OUTLOOK ? (Y/N): %=%[RETURN]

:outlook decision
if /I [%INPUT%]==[Y] goto startoutlook
if /I [%INPUT%]==[N] goto startdeletetemp
if [%INPUT%]==[] goto startdeletetemp

:startoutlook
echo on
echo "Starting Outlook"
echo off
cd "c:\Program files\microsoft office\office10\"
START OUTLOOK.exe

:startdeletetemp
echo on
echo "Start deleting temp files"
Echo off
:TOP
FOR /R "C:\Windows\Temp\" %%G IN (*.exe) DO del "%%G"
FOR /R "C:\Windows\Temp\" %%G IN (*.tmp) DO del "%%G"
FOR /R "C:\Documents and Settings\username\Local Settings\Temp\" %%G IN (*.exe) DO del "%%G"
FOR /R "C:\Documents and Settings\username\Local Settings\Temp\" %%G IN (*.tmp) DO del "%%G"
Echo on
Echo Files deleted from temp on %date% at %time%
Echo off
ping -n 1800 127.0.0.1>nul
GOTO TOP

OLD is GOLD and Batch Programming is simply Brilliant.

No comments:

Post a Comment