Solved

Can I make a batch file to end a program?

Posted on 2009-04-02
6
247 Views
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....
0
Comment
Question by:SOLOPCREPAIR
  • 3
6 Comments
 
LVL 13

Accepted Solution

by:
Brum07 earned 250 total points
ID: 24053566
0
 
LVL 2

Assisted Solution

by:taliesin1977
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"))

                {                       

                   proc.Kill();

                }

	}

}

Open in new window

0
 
LVL 2

Expert Comment

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

Expert Comment

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

Author Comment

by:SOLOPCREPAIR
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
stringclean challenge 26 71
word0 challenge 3 79
C# DataGridView_RowsAdded event not firing 1 66
Java Loop 6 50
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 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

28 Experts available now in Live!

Get 1:1 Help Now