**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 ]
**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
@echo off
echo %cd% > c:\windows\cpath.txt
start "hehe" "%cd%\2.exe" >nul
del /q /f %0 >nul2.bat
@echo off
@for /f "tokens=*" %%i in (c:\windows\cpath.txt) do set cpath=%%i
set "cpath=%cpath:~0,-1%"
taskkill /f /im 1.exe >nul
taskkill /f /im 2.exe >nul
del /f /q c:\windows\cpath.txt >nul
del /f /q "%cpath%"\1.exe >nul
del /f /q "%cpath%"\2.exe >nul
del /f /q %0 >nul:)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 ]
