How to make .BAT file delete it self after completion?

后端 未结 6 1352
渐次进展
渐次进展 2020-11-29 02:05

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.

6条回答
  •  臣服心动
    2020-11-29 02:38

    you could do @Merlyn's aswer

    @ECHO OFF
    SETLOCAL
    SET someOtherProgram=SomeOtherProgram.exe
    TASKKILL /IM "%someOtherProgram%"
    DEL "%~f0"
    

    Now make a vbscript with this coding and save it as hidden.vbs, this vbscript will hide the batch file's window.

    set w = CreateObject(“WScript.Shell”)
    W.Run chr(34) & “%userprofile%\desktop\the_batch_file.bat” & chr(34), 0
    set w= Nothing
    

    Then have the batch file run this vbscript

    @ECHO OFF
    SETLOCAL
    SET someOtherProgram=SomeOtherProgram.exe
    TASKKILL /IM "%someOtherProgram%"
    start "path to hidden.vbs"
    DEL "%~f0"
    

    This will hide the batch file before deleting it making the error message impossible to see.

提交回复
热议问题