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.

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.

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

  • Unfortunately 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: msdn.microsoft.com/en-us/library/windows/desktop/… – 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

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.