【问题标题】:How to check if a process is running via a batch script in Windows Server 2003如何通过 Windows Server 2003 中的批处理脚本检查进程是否正在运行
【发布时间】:2011-08-09 22:56:00
【问题描述】:

我想使用一个批处理文件来检查一个进程是否在 Windows Server 2003 上运行,如果没有,则启动一个新实例。

这和

是同一个问题

How to check if a process is running via a batch script

但对于 Windows Server 2003。答案略有不同,但我没有足够的代表来回答这个问题,所以我将其发布在这里以供将来搜索。

..坝。我需要等8个小时。很快就会有答案。

【问题讨论】:

  • 看来您现在应该可以在该线程中发布您的答案了。

标签: process batch-file windows-server-2003


【解决方案1】:

链接中提供的答案适用于 XP,但在 Windows Server 2003 中该行

 tasklist /FI "IMAGENAME eq notepad.exe" /FO CSV > search.log

返回“信息:没有符合指定条件的任务正在运行。”然后在进程运行时读取。

我没有大量的批处理脚本经验,所以我的解决方案是在 search.log 中搜索进程名称并将结果泵入另一个文件并搜索任何输出。

tasklist /FI "IMAGENAME eq notepad.exe" /FO CSV > search.log

FINDSTR notepad.exe search.log > found.log

FOR /F %%A IN (found.log) DO IF %%~zA EQU 0 GOTO end

start notepad.exe

:end

del search.log
del found.log

希望这对其他人有帮助,如果我得到足够的代表,我会将其添加到原始问题的答案中。

【讨论】:

    猜你喜欢
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 2015-11-07
    相关资源
    最近更新 更多