Killing a windows service - windows

I have a windows service named 'shipper' running which processes files.
In task manager, the Services tab shows the following
name:shipper
PID: 5000
status:running
In the Process tab:
image name: java.exe
user: SYSTEM
When I execute the following:
taskkill /f /PID 5000
task manager (Services tab) shows that the service is stopped.
However, it continues to execute and process files.
Only when I end the process in task manager will the process stop.
Similarly, this will work:
taskkill /f /im "java.exe"
But of course, that kills all java processes.
What is the correct way, using taskkill (or another standard windows command) to kill the process using the name of the service ("shipper" in this case)?
Thanks

Find the processID used by your service:
for /f "tokens=2 delims=:" %%i in ('sc queryex "shipper" ^|findstr PID') do echo %%i
or try a filter TASKKILL /F /FI "services eq shipper"
in addition you may use the following parameter of taskkill:
/T
Tree kill: terminates the specified process and any child processes which were started by it.

Related

what is the difference if we use delete instead of taskkill

taskkill /F /IM java.exe ---I have use this before but I have 2 java.exe and I have to stop only one.
Now I have tried below command
wmic process where ExecutablePath='C:\Dir1\image.exe' delete
What will be the effect of this changw?
It will only kill/stop the process or it will delete anything?

how to kill a cmd process without killing others cmds?

I'm working on a batch file that is supposed to START a process (CMD) and then it should kill the process after finished. Problem is, that Imagename is cmd.exe and the other problem is that it should be running on Jenkins.
This is what I have tested:
Getting PID with wmic using name of window to find process -> Failed at Jenkins
Taskkill by naming the window-> Failed because Jenkins does not
display windows due to security issues.
Taskkill by imagename -> Failed because there are other cmd processes
running at the same time
Taskkill with pid but pid from the last cmd started. -Works but it is
not very safe.
I couldnĀ“t understand how wmic works but as I see, I cannot start a process with a command like with START command.
Conditions:
It can't be kill after some time because I need the output from the
mergetool and sometimes mergetool can take too long.
It should run at same time with other (cmd) processes // Jenkins
My question, is there a way of getting the PID from the START Command?
Here are some questions that helped me a lot!
Windows batch file : PID of last process?
Compare number of a specific process to a number
CODE:
set "console_name=cmd.exe"
set "git_command=%gitcmd% mergetool ^>output.txt"
tasklist /FI "imagename eq %console_name%" /NH /FO csv > task-before.txt
START "mergetool_w" CMD /c %git_command%
tasklist /FI "imagename eq %console_name%" /NH /FO csv > task-after.txt
for /f "delims=, tokens=2,*" %%A in ('fc /L /LB1 task-before.txt task-after.txt') do set pid=%%A
pid=!pid:"=!
echo pid is %pid%
TASKKILL /t /pid %pid% /f
You could actually use findstr for checking what tasks have been added after your start command line, relying on your files task-before.txt and task-after.txt:
findstr /LXVG:task-before.txt task-after.txt
Due to a nasty bug, this might under some circumstances lead to an unexpected output. To prevent that, add the /I option, if you can live with case-insensitive searches:
findstr /ILXVG:task-before.txt task-after.txt
Yes it's very possible. I'm going to take code from my previous awnser on another post here: Stop Execution of Batch File after 20 Seconds and move to Next
I want to first assume "mergetool_w" is the name of the CMD you are opining with the start...
The way you want to go about this is to search the tasklist for your console title and extract the PID# out of the context. The find suffix can be used to "Filter" the results along with tokens=2 to extract only the PID#.
FOR /F "tokens=2" %%# in ('tasklist /v ^| find "mergetool_w"') do set PID=%%#
From there, you can now kill this new window using the taskkill /pid command. The PID# is stored in the string %PID% so the command is simple:
taskkill /pid %PID% /t /f
Finaly, it looks as if you are trying to "Log" the data so feel free to put > text-task.txt where it's needed.

How to kill a java application by it's process id from windows cmd?

when i run the command: taskkill /f /pid 16140
I get this : ERROR: The process "16140" not found.
Right click on Name column in Task Manager, check PID to show PID of processes, then execute taskkill /pid {PID}.
Note that some processes cannot be terminated by taskkill, for example Task Manager.
You can kill a process by the process ID (PID) or by image name (EXE filename).
Open up an Administrative level Command Prompt and run tasklist to see all of the running processes:
C:\>tasklist
Image Name PID Session Name Mem Usage
========================= ======== ================ ============
firefox.exe 26356 Console 139,352 K
regedit.exe 24244 Console 9,768 K
cmd.exe 18664 Console 2,380 K
conhost.exe 2528 Console 7,852 K
notepad.exe 17364 Console 7,892 K
notepad.exe 24696 Console 22,028 K
notepad.exe 25304 Console 5,852 K
explorer.exe 2864 Console 72,232 K
In the example above you can see the image name and the PID for each process. If you want to kill the firefox process run:
C:\>Taskkill /IM firefox.exe /F
or
C:\>Taskkill /PID 26356 /F
The /f flag is kills the process forcefully. Failure to use the /F flag will result in nothing happening in some cases. One example is whenever I want to kill the explorer.exe process I have to use the /F flag or else the process just does not terminate.
taskkill /im myprocess.exe /f
The "/f" is for "force". If you know the PID, then you can specify that, as in:
taskkill /pid 1234 /f
Lots of other options are possible, just type taskkill /? for all of them. The "/t" option kills a process and any child processes; that may be useful to you

How to kill a specific task in windows 2012 server

This is for windows 2012 server. I am trying to kill a specific task running under cmd window.
In this specific case I want to kill SWIMAUX. I have a command prompt open and every time I use taskkill command I get the following error. How can I kill that task?
C:\Siemens\hot_cold_backups>taskkill /f /fi "imagename eq SWIMAUX"
INFO: No tasks running with the specified criteria.
C:\Siemens\hot_cold_backups>taskkill /f /fi "services eq SWIMAUX"
INFO: No tasks running with the specified criteria.
You need to either specify the image name for the process you want to kill or the window title.
If the window has a specific title, then you can use the WINDOWTITLE parameter of the taskkill command
TASKKILL /F /FI "WINDOWTITLE eq SWIMAUX"
To find the image name of a process:
Open task manager and right click on the process you want to kill, and select Go to details
Find the highlighted executable and use it in your taskkill command, eg. taskkill /f /t /im process.exe
step 1:netstat -ano | findstr :
You should be known your PORT number
Step 2:taskkill /PID /F
id will be shown in the end of the TCP connection data in the result of above command

Killing a process with taskkill /F returning code 0

I need to kill a windows process (java.exe). I'm currently using:
taskkill.exe /F /IM java.exe
I need to use the /F option since is a critical process,but in this way I get a return code 1 instead I need a return code 0 (returned when I don't use /F for killing other not critical processes)
how could I fix this problem?
Many thanks
You can try with :
TASKKILL /F /IM "notepad.exe"
You can know more here. Visit this blog too.
Why don't you use PowerShell?
Stop-Process -Name java.exe
From the old command prompt:
powershell -Command "Stop-Process -Name java.exe"
I am using following command on Windows Server 2008R2
Taskkill /IM B2B_Crawler_V2.exe /F
Refer Taskkill and Killing a process in Batch and reporting on success
Execute this in CMD
Get the list of open processes
netstat -a -o -n
And then kill the process on that port with the following command
taskkill /F /PID <pid>

Resources