Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using TASKKILL to close a bunch of EXEs

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,508
Scotland
This might be more of a DOS question than Windows, but I'll ask here first.

When performing certain maintenance tasks, I need to close all the programs currently running on the system. It seems that the DOS [tt]taskkill[/tt] command will be suitable for this. So I have created a batch file as follows:

Code:
taskkill /f /im thunderbird.exe
taskkill /f /im postbox.exe
taskkill /f /im firefox.exe
etc. etc.

This works as far as it goes. But I don't necessarily know in advance which programs will be running, so I need a way of closing every program that happens to be running at the time. I would have thought I could use a wildcard, something like this:
Code:
taskkill /f /im *.*

but this doesn't work. It typically gives the message "The process *.* is not found". I've tried various other combinations of wildcards and switches, but all without success.

Any help would be appreciated.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Won't closing every program kill the OS? The OS depends on certain executables to be running.

This scenario is why installers may reboot with a function that runs immediately at boot, before any other programs have the opportunity to start.
 
Good point, Spamjim. What I really want to do is to close the programs that currently have a window open on the desktop - not background programs or services. I'm beginning to think it's not such a great idea after all.

It also occurs to me not to try to close EXPLORER.EXE as that would probably destroy the Start menu and task bar.

If I can't find any way of doing this, I'll just hard code the names of the programs that are most likely to be running, and handle the others manually.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I think you need to look at PowerShell's Switch function. It's used to handle multiple If statements or, in other terms, it's a replacement of multiple If/Else... If/Else conditions.

To check a single condition, you can just use an If/else statement... but if you want to evaluate several If statements then use Switch.
 
Mike Lewis said:
What I really want to do is to close the programs that currently have a window open on the desktop - not background programs or services.

I think you will really need PowerShell although it is ugly language ..

Try this PowerShell command to list only those programs which have opened window on the dektop, i.e. not background programs:
Code:
Get-Process | Where-Object { $_.MainWindowTitle }
 
I think you will really need PowerShell although it is ugly language.

Yes, I can see why it is considered ugly. On the other hand, it would be a good chance for me to improve my PowerShell knowledge,so I'll give your suggestion a try. Thanks.

That said, I've now written a batch file that uses Taskkill to individually close the main applications that I have more-or-less permanently open on my desktop (email client, browser, sticky notes prog, Visual FoxPro Hel file, etc.) I'm amazed at how fast it is, compared to closing the programs manually. I assume it uses something like the Windows ExitProcess() function (or vice versa), which kills the app stone dead rather than interrogating it to determine if it is safe to close.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike Lewis said:
On the other hand, it would be a good chance for me to improve my PowerShell knowledge,so I'll give your suggestion a try. Thanks.
Yes, that is a very good attitude, as it should be. I appreciate something like that very much.

If you would like to write a PowerShell script to solve the task and you encounter any problems, don't hesitate and ask your questions here in the PowerShell forum:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top