# Killing a process on system startup



## matthewcheck (Sep 26, 2007)

Hi all,

I am trying to write a batch file on Win XP which kills a process after the system boots up. I have tried it with simple file batch file like:


```
@echo off
taskkill /F /IM process.exe
```
and i added the new registry entry in


```
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
```
to run the batch file on system startup. It is all OK with that, but the problem is that at the time of the system startup the process may or may not be running. I just want to make sure that the process is killed after all. I have thought about doing it with some kind of sleep in the batch file, but at the end i've found out that it's not the best way to do it, since the process may be started up after this time period and this should be as quick as possible and i need to be sure that the process get killed. Any help with this??

Thx in advance


----------



## JimmySeal (Sep 25, 2007)

This may be a dumb question, but why don't you just stop the process from starting in the first place?


----------



## matthewcheck (Sep 26, 2007)

JimmySeal said:


> This may be a dumb question, but why don't you just stop the process from starting in the first place?


Well, I have not thought about that option, but how i am able to stop it? The process is started automatically on system startup by the remote process which is common for all of the computers in the domain, so I believe that I do not have the possibility to prevent the process from being started ... Or am I wrong??


----------



## Noyb (May 25, 2005)

RUN > msconfig .... and shut down the ones you don't want ...


----------



## matthewcheck (Sep 26, 2007)

Well, the reason why i am trying to kill this process after the system startup is that it is started by another process, which i cannot stop or prevent to start. So it looks like the only way to prevent the process from running is to kill it everytime when the system starts up. And that is why i am trying to write a batch file, so i don't have to kill the process manually ...


----------



## JohnWill (Oct 19, 2002)

Take a look at PsKill: http://www.microsoft.com/technet/sysinternals/utilities/pskill.mspx


----------



## JimmySeal (Sep 25, 2007)

Hadn't considered it might be starting from somewhere else on the network.

What if you have the batch file loop and go to sleep for short intervals on every iteration until the process is found and killed?
taskkill returns ERRORLEVEL 0 on successfull process termination and nonzero (it appears to be 128) if the process is not found.


----------



## matthewcheck (Sep 26, 2007)

JohnWill said:


> Take a look at PsKill: http://www.microsoft.com/technet/sysinternals/utilities/pskill.mspx


Thanks for your reply, one question, isn't this pskill tool something similar to the one included with Win XP named "taskkill"? Does it provide more options than the taskkill?


----------



## matthewcheck (Sep 26, 2007)

JimmySeal said:


> Hadn't considered it might be starting from somewhere else on the network.
> 
> What if you have the batch file loop and go to sleep for short intervals on every iteration until the process is found and killed?
> taskkill returns ERRORLEVEL 0 on successfull process termination and nonzero (it appears to be 128) if the process is not found.


Hmmm, I have thought about that option, but isn't there more sophisticated solution? What if for example the process didn't get started and the batch will end up in infinite loop? I know, it is really difficult to solve this at first look very simple problem, but there are so much things to think about ... Maybe i will do the for loop with for example 20 loops, and if the process doesn't get started after all, i will exit the loop and continue normally ... Or does anyone have some other solution?


----------



## JohnWill (Oct 19, 2002)

Regarding PsKill, I figured you might want to try another one, since I presume you've already tried the XP version.


----------



## Squashman (Apr 4, 2003)

And Microsoft must have had some reason for buying Sysinternals. Maybe there commnad line tools were inferior to theres. I for one do think PStools are much better options then many of the Builtin utilites of XP.


----------

