中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-05 10:20
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » [Solved] How to make a self-extracting file delete itself
Printable Version  1,981 / 10
Floor1 tclgb Posted 2007-07-07 21:43
初级用户 Posts 26 Credits 76
**Purpose**: Automatically delete 1.exe after self-extraction

**Process**: I created a self-extracting file (such as 1.exe), which only contains a 1.bat. The self-extraction directory is in %systemroot%. I wanted to automatically delete 1.exe after extraction, so I added del /q/f 1.exe. As a result, I couldn't find the path of 1.exe.

Attempt 1: Set the self-extraction directory to. \, which is the current directory. In this way, 1.exe can be automatically deleted, but there will be a certain display delay. This situation is not discussed for the time being;

Attempt 2: Create a 1.bat (content: @echo %cd% > c:\cpath.txt), set it as "Run before extraction", then create a 2.bat
@for /f "tokens=*" %%i in (c:\cpath.txt) do set cpath=%%i
@del /q /f "%cpath%\1.exe"
As a result, the read "%cpath%" is the path where %systemroot% is located, and it failed, heh heh

Attempt 3: Create a 1.bat and 2.bat. Create a self-extracting file 2.exe for 2.bat, and set the extraction directory to %systemroot%; create a self-extracting file 1.exe together with 1.bat and 2.exe, and set the extraction directory to the current directory. The original idea was: use 1.bat to extract the current path and copy 2.exe to the %systemroot% directory, then run 2.exe to delete the generated files. Just when deleting 1.exe, the "Access denied." always appears, and I can't get over this hurdle. I still want everyone to help give some advice, thank you.

**Solution**: The method is like "Attempt 3". The contents of the two files are as follows:
1.bat

2.bat
:)

The code is still a bit messy. I hope everyone doesn't mind. Also, thank you to the brother on floor 9 for the advice.
This code was tested and passed under xp+sp2.

[ Last edited by tclgb on 2007-7-10 at 10:36 PM ]
Floor2 lianjiang2004 Posted 2007-07-07 21:50
金牌会员 Posts 1,884 Credits 3,946
It seems that there is an option in WinRAR to delete the self - contained compressed file.
Floor3 tclgb Posted 2007-07-07 22:00
初级用户 Posts 26 Credits 76
Thank you lianjiang2004, can you be more specific?
Floor4 haiou327 Posted 2007-07-08 01:30
高级用户 Posts 348 Credits 713
Is to delete its own file

[ Last edited by haiou327 on 2007-7-8 at 01:32 AM ]

Attachments
1exe.JPG (38.64 KiB)
Floor5 haiou327 Posted 2007-07-08 01:31
高级用户 Posts 348 Credits 713
Add DEL 1.EXE after BAT, and also add DEL %0,
Use the Phantom mode of QBFC.

[ Last edited by haiou327 on 2007-7-8 at 01:36 AM ]
Floor6 tclgb Posted 2007-07-08 02:58
初级用户 Posts 26 Credits 76
re

Originally posted by haiou327 at 2007-7-8 01:31:
Add DEL 1.EXE after the BAT, and also add DEL %0,
Use QBFC's Phantom mode.

[ Last edited by haiou327 on 2007-7-8 at 01:36 AM ]



Adding DEL %0 is to delete the bat itself, or can't delete the self-extracting file, heh heh

Thanks
Floor7 tclgb Posted 2007-07-09 00:23
初级用户 Posts 26 Credits 76
Still hope brothers can give some suggestions, thank you thank you thank you
Floor8 haiou327 Posted 2007-07-09 01:27
高级用户 Posts 348 Credits 713
Add DEL/q [self-extracting file path and file name] at the end of the batch processing.
Floor9 flyinspace Posted 2007-07-10 12:09
银牌会员 Posts 517 Credits 1,206
Tips:
To delete an executable file,
this file must not be running in the Windows system (the one that is executing cannot be deleted)

This problem can be solved by using delay instructions + writing code.
Floor10 tclgb Posted 2007-07-10 22:38
初级用户 Posts 26 Credits 76
After testing, the delay does not have the expected effect. I don't know if it's due to the local machine. I have to use taskkill.
Floor11 luowei14 Posted 2007-07-13 12:08
初级用户 Posts 98 Credits 193
A friend named 10 had a fresh idea. He used taskkill to end the WinRAR process and reversed to solve this problem. Nice! Add points.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023