VBS script and BAT batch Delete Method

Source: Internet
Author: User

VBS scripts and BAT batch processing methods for self-deletion (suicide)
Delete itself: VBS
Save the following script as selfkill. vbs or selfkill. vbe: Copy codeThe Code is as follows: 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:Copy codeThe Code is as follows: On Error Resume Next 'to prevent 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:Copy codeThe Code is as follows: 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:Copy codeThe Code is as follows: 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;Copy codeThe Code is as follows: @ echo off
Echo % ~ Dp0

2. Use "% ~ Nx0 "to get the file name;Copy codeThe Code is as follows: @ 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!
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.
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 /?
@ 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"
@ Echo off
Del "% ~ Nx0"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.