匹配特定名称和用户的批处理文件中的杀死进程 [英] Kill process in batch file that matches certain name and user

查看:64
本文介绍了匹配特定名称和用户的批处理文件中的杀死进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题要问...希望有人可以提供帮助.

I have a question for ya'll...hopefully someone can help.

背景:我可以说有6个.exe,它们由6个单独的计划任务启动(.exe是根据客户端命名的,看起来像这样-CLIENTNAME_PROGRAM.EXE).出于调度目的,这6个任务在3个独立的用户帐户下运行.意思是,我可以在不同帐户下同时运行2个进程(不能同时在一个ID下运行它们).如果使用一个ID,则必须运行一个ID,等待其结束,然后等待下一个ID.

Background: I have, lets say, 6 .exe's that are launched by 6 separate scheduled tasks (the .exe's are named after a client and look like this - CLIENTNAME_PROGRAM.EXE). Those 6 tasks run under 3 separate user accounts for scheduling purposes. Meaning, I can have 2 processes running at the same time under different accounts (you can't run them simultaneously under one ID). If you use one ID, you have to run one, wait for it to end, then wait for the next one.

问题:我的批处理文件中有一些代码,用于寻找另一个进程并等待其结束...但是,这是在所有进程的.exe名称都相同的情况下编写的(在我们转到CLIENTNAME_PROGRAM.EXE之前,以前只是PROGRAM.EXE).问题是,我刚刚意识到我的%TFProName%变量设置为当前正在尝试运行的客户端的名称...因此,它不查找在当前卡住的同一计算机帐户下运行的任何其他TFProName.这有道理吗?

Issue: I have some code in my batch file which looks for another process and waits for it to end...however, this was written when the .exe name was the same for all processes (used to be just PROGRAM.EXE before we went to CLIENTNAME_PROGRAM.EXE). Problem is, I just realized that my %TFProName% variable is set to the name of the client that is CURRENTLY trying to run...so it's not looking for any other TFProName's running under the same computer account that are currently stuck. Does that make sense?

所以,我需要:

在用户ACCOUNT1下启动CLIENT2_PROGRAM之前,搜索在ACCOUNT1下运行的任何其他* _PROGRAM进程,然后等待其结束.如果运行时间长,请运行powershell脚本杀死上述进程.

下面是我的代码段:

:PRVARCHSTART

tasklist /FI "IMAGENAME eq %TFProName%" | find /I "%TFProName%" >nul

IF ERRORLEVEL 1 (
   echo        **** %TIME% - Another archive process is not running...checking for an import/export          process... **** >> "%logfilefolder%\%logfilename%"
   goto PRVARCHEND
) ELSE (
   echo        **** %TIME% - Another archive is running...please wait...checking again... **** >>    "%logfilefolder%\%logfilename%"
   PING 1.1.1.1 -n 1 -w 5000 >nul
   powershell "& '%scriptdirectory%\KillTFProAdmin.ps1'"
   goto PRVARCHSTART
)
:PRVARCHEND

推荐答案

这是我现在使用的代码,效果很好:

Here is the code I use now, which works great:

    :PRVARCHSTART

tasklist /FI "IMAGENAME eq %TFProName%" | find /I "%TFProName%" >nul

IF ERRORLEVEL 1 (
   echo        **** %TIME% - Another archive process is not running...checking for an import/export          process... **** >> "%logfilefolder%\%logfilename%"
   goto PRVARCHEND
) ELSE (
   echo        **** %TIME% - Another archive is running...please wait...checking again... **** >>    "%logfilefolder%\%logfilename%"
   PING 1.1.1.1 -n 1 -w 5000 >nul
   powershell "& '%scriptdirectory%\KillTFProAdmin.ps1'"
   goto PRVARCHSTART
)
:PRVARCHEND

这篇关于匹配特定名称和用户的批处理文件中的杀死进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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