If cmd.exe exist it should goto :error
Thanks in advance.
-Diddy
tlist | findstr /i "cmd.exe" >nul && echo It's running.
--
Phil Robyn
Univ. of California, Berkeley
u n z i p m y a d d r e s s t o s e n d e - m a i l
The same solution applies:
68) How can I test if a program already has been loaded?
103196 Sep 8 2004 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
In XP one can use Task Manager for the purpose e.g. as follows
@echo off & setlocal enableextensions
tasklist|find "Netscp.exe ">nul
if %errorlevel% EQU 0 (
echo Netscape has been loaded
) ELSE (
echo Netscape has not been loaded)
endlocal & goto :EOF
References/Comments (for NT/2000):
http://www.sysinternals.com/ntw2k/freeware/pstools.shtml
If you are using a script in a command window to call an MS-DOS
program, and you wish to prevent calling that same program
simultaneously from another window/or via shelling (to avoid
datafile or whatever conflicts), you can proceed as shown below. The
script creates a markerfile for the duration of running the script.
@echo off & setlocal enableextensions
if exist %temp%\vpp3d.mrk (
echo Exiting: vpp3d already is running
goto :EOF)
echo Mark vpp3d>%temp%\vpp3d.mrk
::
:: Call whatever program it happens to be
C:\_F\VPP\VPP3D.COM
::
del %temp%\vpp3d.mrk
endlocal & goto :EOF
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
"Phil Robyn" <zipp...@berkeley.edu> wrote in message
news:2u7slvF...@uni-berlin.de...
No, TLIST.EXE (part of the free Resource Kit Support Tools from Microsoft)
runs by itself, not via CMD.EXE.
> I don't have tlist on this box to test this, but wouldn't the execution of
> this always yield a positive result because cmd.exe is launched to run it?
OK, I see what you mean. :-) The OP posted to this newsgroup (alt.msdos.batch.nt)
so I provided a *batch* command, viz.
tlist | findstr /i "cmd.exe" >nul && echo It's running.
Even though TLIST.EXE does not require the launching of another instance of CMD.EXE
to execute, at least one copy of CMD.EXE must of course be running in order to execute
the *batch command* that invokes TLIST....
> I don't have tlist on this box to test this, but wouldn't the
> execution of this always yield a positive result because cmd.exe
> is launched to run it?
So what is the end goal? Since process CMD will exist (for the
batch) why/what do you need actually to determine in the batch. More
details may help generate ideas.
Also: pslist.exe (www.sysinternals.com)
>How to check if there are cmd.exe running before running a script?
>
>If cmd.exe exist it should goto :error
>
>Thanks in advance.
If you are testing in a batch file under one of the NT series
operating systems, the answer is always yes because the batch file is
running under CMD, or if the batch is running under COMMAND.COM, an
instance of CMD will be spawned when you launch either TLIST or
PsList.
Note: this is the first time I have seen that observation about CMD
launching under COMMAND to run Windows console applications. I'm not
sure if it is important, except in the context of your question.
What are you *really* trying to do?
T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
I want to allow my script to be runned only once at time.
To prevent it to be loaded simultaneously the way that Timo described
are not so good. The reason for that is when the script interrupts, it
wont delete that "vpp3d.mrk" file. I need more waterproof solution.
I see that finding out if cmd.exe is running is not so clever because
the script itself uses cmd.exe.
So my question is: Is it possible to see if there are two cmd.exe
running and if there are, then it should quit. Btw.. hopefully this
can be done with Windows XP own command.
-Diddy
You don't really care about CMD, you care about the script - that is
almost trivial.
@echo off
tlist | find "%0" > nul
if not ERRORLEVEL 1 goto :err
:err
error handler goes here
TLIST is supposed to be in this package: <
http://download.microsoft.com/download/win2000platform/utility/1/NT5/EN-US/umdhtools.exe>
but I haven't checked myself.
> @echo off
> tlist | find "%0" > nul
> if not ERRORLEVEL 1 goto :err
>
> :err
> error handler goes here
That's wrong - that's what I get for trying to cram new code into the
last few minutes of the work day.
This is what I was trying to do:
@echo off
tlist | find "foo" > null
if not ERRORLEVEL 1 goto :EOF
title foo
your code goes here
title %~n0
Replace "foo" with whatever marker you want - it has to be unique to
the program, but not the name of the file.
That looks for the working title in a tlist dump - if it is found, the
program is running and has passed the fourth line. If not, either the
program is not running or is in the first few lines. You need tlist
instead of some of the other task listers because it displays the
window title (which line four changes form the default, and the last
line sets to the name of the program, though the Windows default title
would be better).
--
T.E.D. (tda...@gearbox.maem.umr.edu)
You explained the situation better than I did. So, this wouldn't really
achieve the OP's goal as is--that we need to determine if their is a
*second* instance of cmd.exe running, right?
"Phil Robyn" <zipp...@berkeley.edu> wrote in message
news:2u8o77F...@uni-berlin.de...
As with the others, I'm not sure what you are asking either. You could mean
you want to know if an instance of cmd.exe is already running. You could
also mean you want to know if which command processor is currently running.
For the latter, you might examine %COMSPEC% or even try
REM & GOTO :error
--
Todd Vargo (double "L" to reply by email)
I'm not sure what the OP's goal is....
Thanks Ted Davis for that working solution. Seems to work like a charm.
I also like to thank the others for different ways to do it.
-Diddy