Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How VBS scripts and BAT batches delete themselves

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how VBS scripts and BAT batches can delete themselves. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Methods for deleting VBS scripts and BAT batches themselves

Delete your own: VBS

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

The code is as follows:

Set fso = CreateObject ("Scripting.FileSystemObject")

F = fso.DeleteFile (WScript.ScriptName)

WScript.Echo (WScript.ScriptName)

And then run it, did you find that selfkill.vbs magically disappeared? However, the later dialog box is displayed normally.

The above script calls the FSO control, uses the ScriptName property of the Wscript object in WSH, and gets the file name of the script itself.

And call the DeleteFile method of FSO to delete itself!

Rewrite it a little bit:

The code is as follows:

On Error Resume Next 'prevent errors

Set fso = CreateObject ("Scripting.FileSystemObject")

WScript.Sleep 1000 'suspends script execution for 1 second

Fso.DeleteFile (WScript.ScriptName) 'delete the script itself

If fso.FileExists ("c:selfkill.exe") Then fso.DeleteFile ("c:selfkill.exe") 'delete program

The program can dynamically generate a VBS self-deletion script and call it to delete itself, the method is also similar to the self-deletion of batch files!

It should be noted that due to the misuse of scripts by viruses and worms, scripts may be mistaken for malicious code when deleting files!

Attached: self-delete js script:

The code is as follows:

Try {fso = new ActiveXObject ("Scripting.FileSystemObject")

WScript.Sleep (1000); / / dormant for 1 second

Fso.DeleteFile (WScript.ScriptName); / / Delete the script itself

Fso.DeleteFile ("c:selfkill.exe"); / / remove the program

} catch (e) {}

Attached: self-delete js script:

The code is as follows:

Try {fso = new ActiveXObject ("Scripting.FileSystemObject")

WScript.Sleep (1000); / / dormant for 1 second

Fso.DeleteFile (WScript.ScriptName); / / Delete the script itself

Fso.DeleteFile ("c:selfkill.exe"); / / remove the program

} catch (e) {}

Delete yourself: batch processing

Related knowledge:

Summary of the specific application of% 0

In a batch, 0 represents the batch file itself.

In batch processing, you can delete yourself by using the command "del 0".

Taking advantage of this feature, batch processing is often used as a complete uninstall tool.

Of course, we can also use extensions to achieve more uses:

1. The path of the file can be obtained by using "% ~ dp0"

The code is as follows:

@ echo off

Echo% ~ dp0

two。 The file name can be obtained by using "% ~ nx0"

The code is as follows:

@ echo off

Echo% ~ nx0

For example, there is a folder called AAA on my C disk with many files in it.

I want to delete all the files and folders in the g:AAA folder.

Rd / s / q C:AAA

The above line of code happens to solve the problem! (the AAA folder has also been deleted.) see the explanation for details:

Delete a directory.

RMDIR [/ S] [/ Q] [drive:] path

RD [/ S] [/ Q] [drive:] path

/ S in addition to the directory itself, all subdirectories under the specified directory and

Files. Used to delete the directory tree.

/ Q quiet mode, no confirmation is required when deleting the directory tree with / S

Reference: rd/?

@ echo off

Echo% ~ nx0

You'd better put quotation marks in this one, otherwise you can't kill it if there is a space in the middle of the name.

I killed the copy 123.bat.

@ echo off

Del "% ~ nx0"

Thank you for reading! On "VBS scripts and BAT batches how to delete themselves" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report