如何使完成后.bat文件删除它的自我? [英] How to make .BAT file delete it self after completion?
本文介绍了如何使完成后.bat文件删除它的自我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何制作完成后.bat文件删除它的自我?我有一个终止进程一个简单的bat文件。我想这.bat文件删除自身。
解决方案
@ECHO OFF
SETLOCALSET someOtherProgram = SomeOtherProgram.exe
TASKKILL / IM%someOtherProgram%ECHO这个剧本现在将自毁,请忽略接下来的错误消息
DEL%〜F0
请注意,该行DEL最好是你打算里面的批处理文件执行的最后一件事情,否则你的运气了:)
这将打印出一个丑陋的错误消息,但它是良性的,而code是略低于混乱这个样子。如果你很在意摆脱错误信息,请参阅 dbenham的回答来摆脱它。
How to make .BAT file delete it self after completion? I have a simple bat file that terminates a process. I want that .BAT file to delete itself.
解决方案
@ECHO OFF
SETLOCAL
SET someOtherProgram=SomeOtherProgram.exe
TASKKILL /IM "%someOtherProgram%"
ECHO "This script will now self-destruct. Please ignore the next error message"
DEL "%~f0"
Note that the DEL line better be the last thing you intend to execute inside the batch file, otherwise you're out of luck :)
This will print out an ugly error message, but it is benign, and the code is slightly less confusing this way. If you care a lot about getting rid of the error message, see dbenham's answer to get rid of it.
这篇关于如何使完成后.bat文件删除它的自我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文