VBS background Run BAT deletes its own code _vbs

Source: Internet
Author: User
Know the true path of the case

Copy Code code as follows:

Set Fso=wscript.createobject ("Scripting.FileSystemObject")
Fso.deletefile "C:\windows\system32\run.cmd"
Fso.deletefile "C:\windows\system32\run.vbs"


If you do not know the exact path, you can use the following code:

Copy Code code as follows:

Set FSO =createobject ("Scripting.FileSystemObject")
Fso. DeleteFile (Wscript.scriptfullname)


Wscript.scriptfullname returns the actual path of the script.

Delete itself: VBS

Save the following script as Selfkill.vbs or selfkill.vbe:

Copy Code code as follows:

Set fso = CreateObject ("Scripting.FileSystemObject")
f = fso. DeleteFile (WScript.ScriptName)
WScript.Echo (WScript.ScriptName)


And then run it, do you find selfkill.vbs magically disappear? and the dialog behind it is normally displayed. Oh ^*^
The script above invokes the FSO control, using the WScript object in WSH to scriptname the property to get the file name of the script itself.
And call the FSO's DeleteFile method to delete itself!

Rewrite it a little bit:

Copy Code code as follows:

On error Resume Next ' prevents errors
Set fso = CreateObject ("Scripting.FileSystemObject")
Wscript.Sleep 1000 ' to suspend script execution for 1 seconds
Fso. DeleteFile (wscript.scriptname) ' Delete script itself
If FSO. FileExists ("C:\selfkill.exe") Then FSO. DeleteFile ("C:\selfkill.exe") ' Remove program


The program can dynamically generate the VBS delete script and call it to delete itself, and the method is similar to the batch file's self deletion!
It should be explained that because of the misuse of the script by viruses and worms, the script may be mistaken for malicious code when it deletes files.

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.