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.