2

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 enough rep to answer that one so I'll post it here for future searches.

..dam. I need to wait 8 hours. Answer coming soon.

Community
  • 1
  • 1
benmod
  • 361
  • 6
  • 10

1 Answers1

0

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

benmod
  • 361
  • 6
  • 10