K
K
Krill19272019-07-31 13:02:45
cmd/bat
Krill1927, 2019-07-31 13:02:45

How to write a bat nickname with "self-destruction"?

Hello, I'm slowly delving into "computer science".
And I wanted to write something like a virus.
It doesn't really do anything, it just exists.
And after the execution of the "virus", the bat-nick should start.
The purpose of this batch file is to destroy the entire directory in which it is located (instead of itself).
I tried but this is what I got:

Процесс не может получить доступ к файлу, так как этот файл занят другим процессом

The "code" I used:
@echo off
rd /s /q %cd%
pause

PS after this error, the bat-nick itself is deleted, leaving the directory in which it was

Answer the question

In order to leave comments, you need to log in

5 answer(s)
W
wisgest, 2019-07-31
@wisgest

You cannot delete a directory if it (or its subdirectories) is a worker for some process. Before rdtrying to change the working directory:

cd \
rd /s /q %0\..

E
Ezhyg, 2019-07-31
@Ezhyg

For about the same, I use nircmd .
The batch file runs a script for nircmd that removes garbage from the folder, and then deletes the script, the batch file and the nircmd program itself.
Del_AppleTrash.bat

@echo off
echo Удаление огрызочного мусора
nircmd.exe elevatecmd script Del_AppleTrash.ncl

Del_AppleTrash.ncl
execmd del ".DS_Store" /F /S
execmd del "Del_AppleTrash.ncl" /F
execmd del "nircmd.exe" /F
execmd del "Del_AppleTrash.bat" /F

K
keeplod, 2019-07-31
@keeplod

Through the task scheduler.

I
Igor, 2019-07-31
@DMGarikk

dig in the direction of
start "rd / s / q % cd%"
I have nowhere to try, but if you add a delay there, it should work better

K
Konstantin Tsvetkov, 2019-07-31
@tsklab

Deleting yourself: Deleting everything in the launch folder: Deleting the launch folder:

SET AA=%CD%
CD ..\
CMD /C RD /S /Q %AA%

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question