Is there a list of known exit codes (errorlevel) for TaskKill.exe? Does this vary with the Windows version? I'm mostly concerned with Windows 7 and server 2008r2.
Asked
Active
Viewed 1.0k times
2 Answers
2
They probably correspond to standard Windows error codes. If you want to look up the verbose description, run NET HELPMSG nnnn, where nnnn is the exit code.
C:\>taskkill /im notepad.exe
SUCCESS: Sent termination signal to the process "notepad.exe" with PID 12144.
C:\>echo %errorlevel%
0
C:\>net helpmsg 0
The operation completed successfully.
All Win32 error codes are listed in the MSDN documentation:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx

Jeremy Lyons
- 1,088
- 6
- 9
-
1Unfortunately that would require encountering the code then looking it up. I'm scripting this and want to handle the common exit codes appropriately. – chilltemp Apr 10 '13 at 20:55
-
What kind of scripting? I've scripted against errorlevel codes before. Here's the library if you want a reference: http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx – Jeremy Lyons Apr 10 '13 at 20:56
-
It will either end up in a PowerShell script, or as part of a C# Windows Service. My preference is C# (not really a script). – chilltemp Apr 10 '13 at 20:59
-
My real concern is that some programs return non-zero exit codes on success. I don't want to write something that doesn't know the difference between success & failure. – chilltemp Apr 10 '13 at 21:01
-
Some programs do. Are you coding against all programs, or just taskkill.exe? – Jeremy Lyons Apr 10 '13 at 21:14
-
Just a thought, if you're going to use C# rather than a scripting environment, why not look for programmatic ways to achieve your result? If you want to kill tasks, use the Process.Kill() method instead of calling an outside program. This way if it raises an exception, you can handle it appropriately. – Jeremy Lyons Apr 10 '13 at 21:16
-
@chilltemp why in heaven's name do you want to use `TASKKILL` in a Powershell script when there is the native [`Stop-Process`](http://technet.microsoft.com/en-us/library/ee177004.aspx) cmdlet able to perform the same task and offering exception handling? – the-wabbit Apr 11 '13 at 08:14
-
1taskkill.exe can sucessfully kill misbehaving apps that Process.Kill() can't. I'm not sure if Stop-Process can. – chilltemp Apr 11 '13 at 21:45
1
If you're writing your script in PowerShell, why are you 'shelling out' to TASKKILL.EXE. Why not use the Stop-Process cmdlet? You're then in total control of any exception handling, Etc.

Simon Catlin
- 5,232
- 3
- 17
- 20