I am trying to make a fork bomb which closes itself as soon as the flash drive on which it is stored is removed. This is my code so far:
:start
start %0
IF EXIST E:\forkbomb.bat goto start
For some reason it stays open even once the flash drive is removed, why does the condition not become false once the flash drive is no longer inserted and cause the program to exit? Thanks!
Swap line 1 and 2 ;)
It won't technically be a fork bomb anymore but it will still create many windows who will all banish themselves as soon as the flash drive disappears.
Edit, did some further thinking, and you also need another IF.
IF EXIST E:\forkbomb.bat start %0
:start
IF EXIST E:\forkbomb.bat goto start
In fact you could even try your luck with the original fork bomb design.
Conceptually it didn’t work for you probably because every instance had to be past the highlighted line below at the instance the drive was removed:
:start
start %0 <<<< this line
IF EXIST E:\forkbomb.bat goto start
Because if even one of the instances is before the start then it will keep creating new instances (without the loop). So essentially your fork bomb gets degenerated into a situation where each window creates exactly one new window.
tl;dr without further ado here is my amended solution
:begin
IF NOT EXIST E:/forkbomb.bat goto end
start %0
goto begin
:end
Now that is a full fork bomb and when the drive is removed it will clean up itself as fast as possible.
Cheers