I want use a batch file to check if a process is running on Windows Server 2003 and then start a new instance if not.
This is the same question as
How to check if a process is running via a batch script
but for Windows Server 2003. The answer is slightly different, however I don't have enoug开发者_JS百科h rep to answer that one so I'll post it here for future searches.
..dam. I need to wait 8 hours. Answer coming soon.
The answer provided in the link works for XP, however in Windows Server 2003 the line
tasklist /FI "IMAGENAME eq notepad.exe" /FO CSV > search.log
returns "INFO: No tasks are running which match the specified criteria." which is then read as the process is running.
I don't have a heap of batch scripting experience so my soulution is to then search for the process name in search.log and pump the results into another file and search that for any output.
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
Hope this helps someone else, if I get enough rep I'll add it to the original question's answers.
Ben
精彩评论