I need to automate a process where i want to close a program.

When running,

taskkill /IM notepad.exe

from CMD it works fine.

But when i create a batch file in order to do the same thing, it fails. The bat file runs but the program is not closed.

How to fix this issue?

  • 1
    Were you running the command in an Administrative command prompt but you're just double clicking on the batch file so it's not running as admin? If you run the batch file from an administrative command prompt or right click on the batch file and choose "Run as administrator" does it work then. If the notepad was elevated a non elevated batch file would be getting access denied I suspect. You may also want to add the /f switch to force close. E.g. taskkill /F /IM notepad.exe – HelpingHand Oct 17 '17 at 6:48

I found the answer on the sister site StackOverflow.

Try the following:

taskkill /f /im notepad.exe

The comments suggest that /f flag needs to be added to bat file for taskkill to work.

  • Running it elevated as administrator.... I've seen this be resolved doing that with he /f /im switches—add that to your answer and tag me back please. – Pimp Juice IT Oct 18 '17 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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