Delete itself: VBS
Save the following script as selfkill. vbs or selfkill. vbe:
The code is as follows:
The code is as follows: |
Copy code |
Set fso = CreateObject ("Scripting. FileSystemObject ") F = fso. DeleteFile (WScript. ScriptName) WScript. Echo (WScript. ScriptName) |
Then run it. Did you find selfkill. vbs suddenly disappeared? The subsequent dialog box is displayed normally. OH ^ * ^
The above script calls the FSO control and obtains the script file name by using the ScriptName attribute of the Wscript object in WSH,
And call the DeleteFile method of FSO to delete itself!
Rewrite it a bit:
:
The code is as follows: |
Copy code |
On Error Resume Next 'prevents errors Set fso = CreateObject ("Scripting. FileSystemObject ") WScript. Sleep 1000 'suspends the script execution for 1 second Fso. DeleteFile (WScript. ScriptName) 'delete the script itself <! -- More --> If fso. FileExists ("c: selfkill.exe") Then fso. DeleteFile ("c: selfkill.exe") 'deletes a program |
The program can dynamically generate a VBS self-deletion script and call it to delete itself. The same method is similar to the self-deletion of batch files!
It should be noted that due to the abuse of scripts by viruses and worms, the script may be mistakenly mistaken for malicious code when deleting files!
Appendix: self-deleted js script:
The code is as follows: |
Copy code |
Try {fso = new ActiveXObject ("Scripting. FileSystemObject "); WScript. Sleep (1000); // Sleep for 1 second Fso. DeleteFile (WScript. ScriptName); // delete the script itself Fso. DeleteFile ("c: selfkill.exe"); // delete a program } Catch (e ){} |
Appendix: self-deleted js script:
The code is as follows: |
Copy code |
Try {fso = new ActiveXObject ("Scripting. FileSystemObject "); WScript. Sleep (1000); // Sleep for 1 second Fso. DeleteFile (WScript. ScriptName); // delete the script itself Fso. DeleteFile ("c: selfkill.exe"); // delete a program } Catch (e ){} |
Delete itself: Batch processing
Related knowledge:
Application Summary of % 0
In batch processing, % 0 indicates the batch processing file itself.
In batch processing, run the "del % 0" command to delete itself.
With this feature, batch processing is often used as a full uninstall tool.
Of course, we can also use extensions for more purposes:
1. Use "% ~ Dp0 "to get the path of the file;
The code is as follows: |
Copy code |
@ Echo off Echo % ~ Dp0 |
2. Use "% ~ Nx0 "to get the file name;
The code is as follows: |
Copy code |
@ Echo off Echo % ~ Nx0 |
For example, a folder named AAA on drive C contains many files.
I want to delete all files and folders in the g: AAA folder. How can I write batch processing!
The code is as follows: |
Copy code |
Rd/s/q C: AAA
|
The above line of code exactly solves the problem! (The folder AAA is also deleted.) for details, see the description:
Delete a directory.
The code is as follows: |
Copy code |
RMDIR [/S] [/Q] [drive:] path RD [/S] [/Q] [drive:] path
|
In addition to the Directory,/S also deletes all subdirectories and
File. Used to delete a directory tree.
/Q Quiet mode. Confirmation is not required when/S is used to delete the directory tree.
Reference: rd /?
The code is as follows: |
Copy code |
@ Echo off Echo % ~ Nx0
|
It is best to add quotation marks. Otherwise, the name cannot be killed with spaces in the middle.
I killed "duplicate 123.bat"
The code is as follows: |
Copy code |
@ Echo off Del "% ~ Nx0"
|