Articles

kill a process from command line

March 21, 2006 at 14:58:55
Specs: windowsXP, petium III/ram 256

Hi,
Can some one help me with this?
I scheduled a task from Win xp "Scheduled tasks". This job is will open a reflection window( an application for unix) and doing some other jobs.
I want to run it dailly. Now I am having problem:
I can run it at first time it's ok, but I can't close up that window so my scheduled task is in runing status, which blocked my next run.
I want to find out a way to kill that window.
I can see this application runing from task manager. My question is how can I kiil/ close that window from command line?
Please help. Thanks in advance

See More: kill a process from command line

Report •


#1
March 21, 2006 at 15:01:05

or something can run this in background?

Report •

#2
March 21, 2006 at 20:11:42

You'll need to run these two commands:
tasklist
taskkill

You'll see the process using tasklist. A PID will be shown next to the process and by running taskkill you will be able to kill it. (I am assuming that the built-in commands in XP are similar to System Internal's pslist and pskill).


Report •

#3
March 22, 2006 at 09:28:13

Thanks for your advice Astroraptor.
Yes, I could use tasklist and taskkill
but the problem is how should I do it.
Here is my situation:
I am runing an application called reflection. When it runing window shows r2win.exe is runing from my tasklist.
when I auto run my script named "test" it will bring another widow up and add another r2win.exe in tasklist ( I have serveral r2win.exe runing-- I don't want to kill then all)
So I need to use specific PID to kill the one my "test" created.. How can I tell which PID is from my "test". the PID # seems to be the latest but not the biggest.
if I use taskkill /f /im r2win.exe it would kill all of my r2win.exe section

BTW, on task manager wiondow I can see it shows my "test" is runing-- buy from task list only shows r2win.exe.

Is there anyway I can kill specific PID ( I don't know which PID is belong to my "test")

Any help is appreciated.



Report •

Related Solutions

#4
March 22, 2006 at 13:12:06

For /F "tokens=2" %%n in ('tasklist ^| Find "r2win.exe"') Do Set Task=%%n
TaskKill %task%
Set Task=
----
Assuming that TaskList lists all processes based on launch order as does PSList, this will extract the PID and set the last found PID of r2win.exe as %task% which will then be killed by TaskKill. Careful, using Find, you must use the exact case of the EXE file in question. It should always remain the same however. If that doesn't work, try manually looking at the case of r2win.exe.

Report •

#5
March 22, 2006 at 16:00:50

Thanks Astroraptor.
I got another issue now.
I trying to combine my script into batch script like this:
**************
echo hello -- start
test.r2w -- my script to be run
For /F "tokens=2" %%n in ('tasklist ^| Find "r2win.exe"') Do Set Task=%%n
TaskKill %task%
Set Task=
echo hello I am finished
**************
The proble is my script couldn't ended so the script is hang there
the for... part is not get excuted.
May be I'll need to use 2 seperated script?
1 my test.r2w
2 batch one to kill( end) my script?

Please help.


Report •

#6
March 22, 2006 at 18:46:02

Have you run this from the command-line to see if an error is displayed?

Report •

#7
March 25, 2006 at 20:46:37

Hi Astroraptor,
Sorry I was quite busy last few days.
I tried this seperately and it's working fine.
I did like this:
================
script1 "test":
echo hello
notepad.exe

script 2 kill:
For /F "tokens=2" %%n in ('tasklist ^| Find "notepad.exe"') Do Set Task=%%n
TaskKill /PID %task%
Set Task=
echo hello I have kill the test
====================================
It is working fine
But if I put it into one script it will stop at notepad.exe running -- the kill process can't get executed
To use 2 scripts is ok but I need the second script run after the first one finish -- which I don't know when the first one is done.
Please help


Report •

#8
March 27, 2006 at 15:58:47

Thanks Astroraptor.
I got another issue now.
I trying to combine my script into batch script like this:
**************
echo hello -- start
test.r2w -- my script to be run
For /F "tokens=2" %%n in ('tasklist ^| Find "r2win.exe"') Do Set Task=%%n
TaskKill %task%
Set Task=
echo hello I am finished
**************
The proble is my script couldn't ended so the script is hang there
the for... part is not get excuted.
May be I'll need to use 2 seperated script?
1 my test.r2w
2 batch one to kill( end) my script?

Please help.


Report •

#9
March 27, 2006 at 16:03:09

I figured I can write a marker file at the end of script 1 and in script 2 I can search if the marcker file is exist. If yes then execute the kill section.
But can youi help me on how to do the checking
Thanks a lot

Report •

#10
March 28, 2006 at 11:01:52

I figured I can write a marker file at the end of script 1 and in script 2 I can search if the marcker file is exist. If yes then execute the kill section.
But can youi help me on how to do the checking
Thanks a lot

Report •


Ask Question