what is the difference if we use delete instead of taskkill - shell

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?

Related

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

Difference between taskkill and taskkill /f

On Microsoft Technet I can read that taskkill has a /f parameter to kill a process forcefully. I wonder what this does internally, to understand the impact of such an action.
taskkill (without /f) does not simply send a WM_CLOSE message to the process, otherwise my application would ask whether or not to save the open documents. This makes me assume that it already operates on a TerminateProcess (MSDN) level. However, TerminateProcess does not have a parameter for forcing a kill.
So, what do taskkill and taskkill /f do internally?
I read the related question Difference between C# Process.Kill() and Taskkill but it does not have an answer.
Most likely taskkill /f uses TerminateProcess, where as taskkill without /f just posts a WM_QUIT message (not WM_CLOSE). The docs says that TerminateProcess unconditionally kills the process.
You can try following experiments:
Launch notepad.exe and type a few chars in the notpad window
Type taskkill /f /im notepad.exe. Notepad will quit immediately
Now do this:
Launch notepad.exe and type a few chars in the notpad window
Type taskkill /im notepad.exe. Notepad won't quit immediately but it will quit ask if you want to save modifiactions.

Killing a windows service

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.

Batch script to close all open Command Prompt windows

I have a .cmd file which I call to open multiple instances of Command Prompt via:
launcher.cmd -fs
launcher.cmd -tds
launcher.cmd -fsd
Each command open a new command prompt.
So what I want to do is create a batch file to automatically close all the opened Command Prompt instead of manually doing it.
Be carefull: you might kill more processes than you want:
taskkill /IM cmd.exe
You can add extra filters:
taskkill /IM cmd.exe /FI "WINDOWTITLE eq launcher*"
use
tasklist /FI "imagename eq cmd.exe " /V
to get a glimpse of what cmd.exe processes will be taskkill-ed
You could add the /F parameter to force the process to close but I would only use that if the process doesn't respond to a normal request.
Just a little note why accepted answer from Rene may not work. I was starting my apps from cmd file like
start "" my.exe -my -args
where my.exe was a console app and it was looking like cmd window I wanted to kill, but process name was not cmd.exe (!) and I had to use command like
taskkill /IM my.exe
So in some cases it worth to check the real process name, for example in the windows task manager.
TASKKILL /F /IM cmd.exe /T
good solution

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