批量重新打开文件 [英] Re-opening files in Batch

查看:53
本文介绍了批量重新打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于绝对不是恶意的原因,我需要始终打开一个批处理文件. 我有一些基本代码:

For definitely not malicious reasons, I need to have a batch file always open. I have some base code:

:b

echo off

tasklist /fi "imagename eq cmd.exe" |find ":" > nul

if errorlevel 1 taskkill /f /im "game.bat"&start game.bat

goto b

如果想要notepad.exe或blah.txt等,它也可以正常工作. 除批处理文件外,由于程序本身是批处理文件, 系统会看到cmd.exe已经打开.

And it works fine if want notepad.exe or blah.txt and etc. Except for batch files, as the program itself is a batch file, the system sees cmd.exe is already open.

推荐答案

除批处理文件外,它均有效,因为系统会看到cmd.exe已打开.

  1. 通过将以下命令添加到game.bat,为批处理文件提供Title:

  1. Give your batch file a Title by adding the following command to game.bat:

title %~nx0

  • 通过将tasklist/v选项一起使用来检查game.bat是否正在运行:

  • Check if game.bat is running by using tasklist with /v option:

    :b
    @echo off
    tasklist /v | find "game.bat" > nul
    rem errorlevel 1 means game.bat is not running, so start it
    if errorlevel 1 start game.bat
    rem timeout to avoid excessive processor load
    timeout 60
    goto b
    


  • 进一步阅读

    • Windows CMD命令行的AZ索引-与Windows cmd行相关的所有内容的绝佳参考.
    • 任务列表-任务列表显示所有正在运行的应用程序和服务及其进程ID(PID),这可以可以在本地或远程计算机上运行.
    • 超时-延迟执行几秒钟或几分钟,以在批处理文件中使用.
    • 标题-更改显示在CMD窗口上方的标题.

    • Further Reading

      • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
      • tasklist - TaskList displays all running applications and services with their Process ID (PID) This can be run on either a local or a remote computer.
      • timeout - Delay execution for a few seconds or minutes, for use within a batch file.
      • title - Change the title displayed above the CMD window.
      • 这篇关于批量重新打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆