How to Fix: Gracefully Close Thunderbird using Batch Script

Dennis Faas's picture

Infopackets Reader Steve T. writes:

" Dear Dennis,

I am trying to backup my Mozilla Thunderbird emails using an automated backup schedule. The problem is that Thunderbird is always running on my computer and there does not seem to be a way to gracefully close the program so that the backup can start. Without closing the Thunderbird before the backup, I run the risk of having corrupt backups due to files being in use. Can you please tell me if there is a way that I can gracefully close Thunderbird (without terminating the process unexpectedly) so that I can complete my automated backups? "

My response:

I had to do a bit of research on this and the answer is that there isn't a way to gracefully close Thunderbird - at least not using a command line parameter, for example. That said, after some stumbling around I've come up with some insight.

The Windows command "taskkill /im" by default will attempt to gracefully close a process whenever possible. Based on my experience this will close Thunderbird windows (such as a new composition, for example), but does not close the parent Thunderbird process.

To get the parent Thunderbird process to close, you will need to execute the "taskkill /im" command the number of times for each open Thunderbird window (for example: a new composition), followed by "taskkill /f /im" to kill the parent process. This should essentially gracefully close Thunderbird.

At this time I do not know of a way to count the number of open Thunderbird windows (as "tasklist" only shows 1 actively running task even if there are 10 open windows); as such, using a "for loop" with a finite number of "taskkill /im" should be able to get the job done.

How to Fix: Gracefully Close Thunderbird using Batch Script

You can use the following batch script to gracefully close 10 Thunderbird windows, then forcefully close it:

@echo off

for /l %%x in (1, 1, 10) do (
  rem echo Loop iteration count %%x
  taskkill /im thunderbird.exe
)

taskkill /f /im thunderbird.exe

If not using a batch file (such as outputting the above code directly the command line), don't use double percentage marks, otherwise the for loop won't work.

I hope that helps.

Got a Computer Question or Problem? Ask Dennis!

I need more computer questions. If you have a computer question -- or even a computer problem that needs fixing -- please email me with your question so that I can write more articles like this one. I can't promise I'll respond to all the messages I receive (depending on the volume), but I'll do my best.

About the author: Dennis Faas is the owner and operator of Infopackets.com. With over 30 years of computing experience, Dennis' areas of expertise are a broad range and include PC hardware, Microsoft Windows, Linux, network administration, and virtualization. Dennis holds a Bachelors degree in Computer Science (1999) and has authored 6 books on the topics of MS Windows and PC Security. If you like the advice you received on this page, please up-vote / Like this page and share it with friends. For technical support inquiries, Dennis can be reached via Live chat online this site using the Zopim Chat service (currently located at the bottom left of the screen); optionally, you can contact Dennis through the website contact form.

Rate this article: 
Average: 5 (6 votes)