教程集 www.jiaochengji.com
教程集 >  操作系统  >  windows  >  正文 VBS脚本和BAT批处理自身删除的方法

VBS脚本和BAT批处理自身删除的方法

发布时间:2020-04-28   编辑:jiaochengji.com
教程集为您提供VBS脚本和BAT批处理自身删除的方法 等资源,欢迎您收藏本站,我们将为您提供最新的VBS脚本和BAT批处理自身删除的方法 资源
本文章分享一篇关于VBS脚本和BAT批处理自身删除的方法 有需要的同学可以测试一下,不过要注意哦不要把机器重要文件删除了哦。
<script>ec(2);</script>

删除自身之:VBS
把下面的脚本保存为selfkill.vbs或selfkill.vbe: 
代码如下:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6425')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6425>Set fso = CreateObject("Scripting.FileSystemObject")
f = fso.DeleteFile(WScript.ScriptName)
WScript.Echo( WScript.ScriptName) </td> </tr> </table>

然后运行它,是不是发现selfkill.vbs神奇的消失啦?而后面的对话框却被正常显示出来噢^*^
上面的脚本调用FSO控件,使用WSH中Wscript对象得ScriptName属性,得到脚本自身的文件名,
并调用FSO的DeleteFile方法删除自身!
把它稍微改写一下:
:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4652')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4652>On Error Resume Next '防止出现错误
Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Sleep 1000 '将脚本执行挂起1秒
fso.DeleteFile(WScript.ScriptName) '删除脚本自身<!--more-->
If fso.FileExists("c:selfkill.exe") Then fso.DeleteFile("c:selfkill.exe") '删除程序 </td> </tr> </table>

程序就可以动态生成VBS自删除脚本,并调用它删除自身啦,方法同样和批处理文件的自删除相似!
需要说明的是由于病毒及蠕虫对脚本的滥用,脚本删除文件时可能会被被误认为恶意代码!
附:自删除js脚本:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2287')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2287>try{fso = new ActiveXObject("Scripting.FileSystemObject");
WScript.Sleep(1000);//休眠1秒
fso.DeleteFile(WScript.ScriptName);//删除脚本自身
fso.DeleteFile("c:selfkill.exe");//删除程序
}catch(e){} </td> </tr> </table>

附:自删除js脚本:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1358')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1358>try{fso = new ActiveXObject("Scripting.FileSystemObject");
WScript.Sleep(1000);//休眠1秒
fso.DeleteFile(WScript.ScriptName);//删除脚本自身
fso.DeleteFile("c:selfkill.exe");//删除程序
}catch(e){} </td> </tr> </table>

删除自身之:批处理
相关知识:
%0的具体应用小结
在批处理中,%0即代表批处理文件本身。
在批处理中,使用命令“del %0”即可达到删除自身的目的。
利用此特性,批处理经常被用来做完全卸载工具。
当然,我们还可以利用扩展,获得更多的用途:
1.利用“%~dp0”可以得到该文件的路径;

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6257')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6257>@echo off
echo %~dp0 </td> </tr> </table>

2.利用“%~nx0”可以得到文件名;

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4973')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4973>@echo off
echo %~nx0 </td> </tr> </table>

如我C盘有个文件夹名为 AAA 里面有很多文件
我想把 g:AAA 这个文件夹里的文件和文件夹全删除该怎么写批处理啊!

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1757')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1757>rd /s /q C:AAA
</td> </tr> </table>

上面一行代码恰好能解决问题!(也删掉了AAA这个文件夹)详见解释:
删除一个目录。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7979')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7979>RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
</td> </tr> </table>

/S 除目录本身外,还将删除指定目录下的所有子目录和
文件。用于删除目录树。
/Q 安静模式,带 /S 删除目录树时不要求确认
参考资料:rd/?

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6090')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6090>@echo off
echo %~nx0
</td> </tr> </table>

这个最好把引号加上,不然名字中间有空格就杀不成了
我杀 "复件 123.bat"

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3346')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3346>@echo off
del "%~nx0"
</td> </tr> </table></td> </tr> </table>

您可能感兴趣的文章:

[关闭]
~ ~