Can I make a batch file to end a program?

Posted on 2009-04-02
Last Modified: 2013-11-10
I have an app that i use that requires a network connection. My laptop will lose the wireless connection 2 or 3 times a day but it immediately reconnects. The problem is once it has lost the connection you have to reopen the app for it to work again, but after losing the connection you can't even close the app without doing a ctrl/alt/del end task because it just pops up errors everytime you try to hit close... It would be nice if I could have a little batch file on my desktop that i could hit to end the task instead of having to go into ctrl/alt/del etc....
  • 3
LVL 13

Accepted Solution

Brum07 earned 250 total points
ID: 24053566

Assisted Solution

taliesin1977 earned 250 total points
ID: 24053589
Not sure that a *simple* batch file can do that.

But here is a C# snippet to kill all instances of Excel. Substitute the process name you see in the task manager for "EXCEL".

1) Save this file as killMyApp.cs
2) Compile it from the command line with "csc /target:exe killMyApp.cs. This will generate killMyApp.exe
3) If this exe is some some path, C:\MyScripts\ for example, create a file with a .bat extension that contains only the line: C:\MyScripts\killMyApp.exe

class killMyApp


	static void Main(string[] args)


		foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName("notepad"))






Open in new window


Expert Comment

ID: 24053601
Hehe, sorry, I didn't want to kill Excel on my machine, so I substituted "notepad" in the snippet above

Expert Comment

ID: 24053616
Or you can just create a shortcut to the exe file

Author Comment

ID: 24169625
Thank you all, I am going to try some of these suggestions when I get back to the clients office... Will post results and accept an answer.

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now