MozillaZine

How to Close Firefox (or any program) at Command Line/Prompt

Discuss various technical topics not related to Mozilla.
frankvii
 
Posts: 3
Joined: May 21st, 2015, 8:12 am

Post Posted May 21st, 2015, 9:47 am

Firefox for Windows doesn't have a command line option to close it. However, I've found two methods that can be used to close it (or any other program) from a command line/prompt. The first method requires using a free, small (43 kb), DOS enhancer program called NIRCMD. The second uses TaskKill which is a native Windows 7 process.

For NIRCMD: You need to download the file from http://nirsoft.net/utils/nircmd.html . Put nircmd.exe in a convenient location, like C:\Windows (Note: nircmd.exe, uses a message box for errors while nircmdC.exe doesn't, that's the only difference). Run firefox and in "Options" insure the warnings for closing tabs are NOT selected (it will prevent closing). Now, a command line of " nircmd.exe closeprocess firefox.exe " will gracefully close Firefox.

For TaskKill: All you have to do is, at the command line, enter " TASKKILL /F /IM firefox.exe /T ". This had the advantage of working without an additional piece of software and not requiring a change in Firefox tab options. A disadvantage MAY (a guess on my part) is that it could corrupt a firefox file that is being updated at the moment (e.g. a cache file). I've tried to research this possibility but didn't turn up anything.

As mentioned, since NIRCMD and TASKKILL are generic programs, they can be used on any other running program. NIRCMD has an additional advantage in that it is a Swiss Army knife of programs. It does almost everything that you had always wished DOS could do. It includes a CHM file that contains examples and seems to include all possible uses of NIRCMD.

If you are reading this, then you have your specific reasons for wanting to close firefox from a command line. I am using it as part of a backup script and firefox must be closed to perform a full backup.

DanRaisch
Moderator

User avatar
 
Posts: 119417
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted May 21st, 2015, 2:21 pm

Moving to MozillaZine Tech as this is not really a Firefox Support issue.

trolly
Moderator

User avatar
 
Posts: 39892
Joined: August 22nd, 2005, 7:25 am

Post Posted May 21st, 2015, 2:28 pm

To clarify the usage of taskkill:
taskkill /F instructs the OS to immediately stop the process and remove it from memory. All currently active operations are aborted (program buffers are not flushed which can lead to incomplete files, system locks may not be released and such things).
The SQLite databases in firefox automatically recover from such states on next start, unless in very severe failures. But the last change may be lost.
If you want a graceful shutdown do not use the /F (force) flag but the process may not obey (e.g. firefox may ask the user if it should close all windows and tabs).

The technical background:
The normal, graceful shutdown simply sends a "window close" command to the main window. This is the same as clicking on the X button in the top right corner.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.

malliz
Folder@Home

User avatar
 
Posts: 43467
Joined: December 7th, 2002, 4:34 am
Location: Australia

Post Posted May 21st, 2015, 2:42 pm

Stupidist thing I have read in a long time good way to corrupt any number of programs and files. Do not follow this advice
You have been warned
What sort of man would put a known criminal in charge of a major branch of government? Apart from, say, the average voter.
"Terry Pratchett"

patrickjdempsey

User avatar
 
Posts: 23734
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC

Post Posted May 21st, 2015, 2:56 pm

Especially ironic given that it's being used in conjunction with a backup script. Doing this will ensure that your backups will mostly contain corrupted files.
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/

malliz
Folder@Home

User avatar
 
Posts: 43467
Joined: December 7th, 2002, 4:34 am
Location: Australia

Post Posted May 21st, 2015, 3:21 pm

The only way you could do potentially more damage is by pulling the power cord
What sort of man would put a known criminal in charge of a major branch of government? Apart from, say, the average voter.
"Terry Pratchett"

frankvii
 
Posts: 3
Joined: May 21st, 2015, 8:12 am

Post Posted May 21st, 2015, 5:32 pm

patrickjdempsey wrote:Especially ironic given that it's being used in conjunction with a backup script. Doing this will ensure that your backups will mostly contain corrupted files.


Just to clarify, I am using NIRCMD to close firefox, not Taskkill. In researching how to close Firefox, the only solution I could find on the internet was the Taskkill option which, as I stated, seemed like it could possibly corrupt firefox. In the past I have used NIRCMD for a number of other things and it occurred to me that perhaps it could also close firefox, which it can, and it does so in a normal manner. So I posted what I found here.

Obviously the consensus, including the moderators, is not to use Taskkill. With a free NIRCMD, there is really no reason to.

malliz
Folder@Home

User avatar
 
Posts: 43467
Joined: December 7th, 2002, 4:34 am
Location: Australia

Post Posted May 21st, 2015, 5:37 pm

You obviously have no idea what tasks Firefox goes through when shutdown correctly and yet you still decided to give inherently bad advice on a public forum to promote a free program please don't do that.
What sort of man would put a known criminal in charge of a major branch of government? Apart from, say, the average voter.
"Terry Pratchett"

morat
 
Posts: 2663
Joined: February 3rd, 2009, 6:29 pm

Post Posted May 21st, 2015, 6:57 pm

@frankvii

A good solution. I tried the following command and I got a "Confirm close" dialog as expected.

Code: Select all
nircmdc.exe closeprocess firefox.exe

http://nirsoft.net/utils/nircmd2.html#closeprocess
Last edited by morat on May 22nd, 2015, 6:26 am, edited 1 time in total.

frankvii
 
Posts: 3
Joined: May 21st, 2015, 8:12 am

Post Posted May 22nd, 2015, 5:30 am

malliz wrote:You obviously have no idea what tasks Firefox goes through when shutdown correctly and yet you still decided to give inherently bad advice on a public forum to promote a free program please don't do that.


Look, what you call "advise" and promoting a program is just me trying to share the only two options I could find that would shutdown firefox from the command-line. This topic was originally posted in the Firefox Support/Help section but the moderator moved it here. However, the Tech section is an area where I would NEVER post. I am certainly no Tech (of any kind) and, you are right, I do NOT know the tasks Firefox goes through to shutdown. However, the "inherently bad advise" I gave included the following: "A disadvantage MAY (a guess on my part) is that it could corrupt a firefox file... I've tried to research this possibility but didn't turn up anything". I think this shows an admitted lack of knowledge, that I searched for this knowledge and gave an appropriate corruption warning (based upon my limited knowledge).

One final comment, I'd like to thank Trolly, the Moderator. The reply given shared what I couldn't find,that is, how Taskkill might corrupt firefox.

trolly
Moderator

User avatar
 
Posts: 39892
Joined: August 22nd, 2005, 7:25 am

Post Posted May 22nd, 2015, 6:04 am

No need for name calling.
We all know now what was intended. And the problem is solved now.

Just as information what can be corrupted and its resolution:
- cache -> it is deleted and recreated.
- cookies -> deleted (usually), strange malfunctions may require manual removal
- databases -> reconstructed with possible loss of last change
- occasionally the profile lock file is not removed -> must be manually removed to be able to use the profile again

I guess that's the important parts.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.

sludge7071-g
 
Posts: 15
Joined: May 9th, 2016, 10:18 am

Post Posted December 28th, 2017, 3:04 pm

So the conclusion is:

The command line of "nircmd.exe closeprocess firefox.exe" is fine . . . Taskkill is bad

DanRaisch
Moderator

User avatar
 
Posts: 119417
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted December 28th, 2017, 4:37 pm

And that conclusion is from two years ago.

Locking this thread due to the age of the original posts.

Return to MozillaZine Tech


Who is online

Users browsing this forum: No registered users and 3 guests