Script that checks for processes and stops. Can it stop the processes if any opened.

Hi,

Script that checks for processes and stops. Can it stop the processes if any opened.
Can anyone help changing the script to stop any process thats in the list.

Regards
Sharath
@Echo Off

net stop "Windows Search"

REM Delete Exisitng Temp File
if exist %TEMP%\proc.txt del %TEMP%\proc.txt /q

REM Clear Process Counter
set /a proc=0

\\dev\profilemanager\pslist /accepteula > %TEMP%\proc.txt

Echo Checking for Outlook

find /i "Outlook" %TEMP%\proc.txt 

if not errorlevel 1 Set /a proc=%proc%+1

Echo Checking for Communicator

find /i "communicator" %TEMP%\proc.txt 

if not errorlevel 1 Set /a proc=%proc%+2

Echo Checking for Desktop Search

find /i "searchindexer" %TEMP%\proc.txt 

if not errorlevel 1 Set /a proc=%proc%+3

if %proc%==1 Goto OutlookFound

if %proc%==2 Goto CommFound

if %proc%==3 Goto SearchFound

if %proc%==4 Goto OutlookSearchFound

if %proc%==5 Goto CommSearchFound

if %proc%==6 Goto OutlookCommSearchFound

Echo No Process running

Echo Starting Profile Manager

:PROFMAN

\\dev\profilemanager\profilemgr.exe /logpath=\\dev\profilemanager\logs1

Goto End

:OutlookFound

cls

Echo Outlook is Running. Please Close Outlook before running batch file again.

Pause.

Goto End

:CommFound

cls

Echo Communicator is Running. Please Close Communicator before running batch file again.

Pause.

Goto End

:SearchFound

cls

Echo Desktop Search is Running. Please Close Desktop Search before running batch file again.

Pause.

Goto End

:OutlookSearchFound

cls

Echo Outlook and Desktop Search are Running. Please Close these before running batch file again.

Pause.

Goto End

:CommSearchFound

cls

Echo Communicator and Desktop Search are Running. Please Close these before running batch file again.

Pause.

Goto End

:OutlookCommSearchFound

cls

Echo Outlook, Communicator and Desktop Search are Running. Please Close these before running batch file again.

Pause.

Goto End

:End
del %TEMP%\proc.txt /q

Pause

Open in new window

LVL 11
bsharathAsked:
Who is Participating?
 
Bill PrewCommented:
Okay, see if this meets your needs.  You will need the pskill utility.

~bp
@echo Off
 
rem Define list of conflicting programs to check for
set "Conflicts=Outlook Communicator SearchIndexer"
 
rem Stop Windows Search service
net stop "Windows Search"
 
rem Kill any of the conflicting processes if running
for %%A in (%Conflicts%) do (
  \\machine\folder\pslist /accepteula %%A >NUL
  if %errorlevel% == 0 (
    \\machine\folder\pskill /accepteula %%A >NUL
  )
)
 
rem Execute the profile manager 
\\machine\folder\profilemgr.exe /logpath=\\machine\folder\logs

Open in new window

0
 
Bill PrewCommented:
I'm busy today repair computers affected by the McAfee problem yesterday, but will add that logic to my improved version of this code posted in earlier question http://www.experts-exchange.com/Programming/Languages/Q_25553307.html later today when I free up a little time.  Should be doable.

~bp
0
 
abt-itCommented:
If it's a service behind the process try "sc stop servicename". To close an applikation, try the command taskkill
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.