批处理:阻止重复进程

我先运行了一个程序a.exe,进程中出现a.exe。现在我想知道如何编一个批处理文件一直监视,使我无法再次打开a.exe,而刚开始打开的a.exe照常运行。各位大虾请多多指教。
或者有n个a.exe程序的进程,如何用批处理使进程中只留下一个a.exe。

第1个回答  2009-06-22
@echo off&set/a n=0
setlocal enabledelayedexpansion
for /f "tokens=1-2" %%a in ('tasklist')do (
if /i "%%a"=="a.exe" set/a n+=1
if !n! geq 2 if /i "%%a"=="a.exe" taskkill /f /pid %%b
)
call %0

你可以改成QQ进行测试,~~~~100%通过~~~~~~~
第2个回答  2009-06-21
假设a.exe在D盘

@echo off
:start_
set n=0
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in ('tasklist.exe^|find /i "a.exe"') do (
set /a n+=1
)
echo 有!n!个a.exe进程
if !n! equ 0 start "" D:\a.exe
if !n! gtr 1 taskkill.exe /im a.exe /f&&start "" D:\a.exe
ping -n 3 127.0.1 >nul 2>nul
endlocal
goto start_本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网