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!

Shutting down an Application (.exe) while it's running

Status
Not open for further replies.

790213

Programmer
Sep 22, 2003
50
0
0
ZA
Hi Guys,

I need to shut down an application (.exe) while it's open from a separate application thereby forcing it to close and taking it out of memory so I can update it. Does anyone know how to do this in code?
 
Use Process class to identify the process to kill by calling for example Process.GetProcessesByName().
You can call Kill() and CloseMainWindow() only for processes that are running on the local computer
Kill() - to terminate imediatelly but it is recommended to terminate processes that do not have graphical interfaces.
The CloseMainWindow() method does the job if your app is a well-formed application.
Kill ()`forces a termination of the process, while CloseMainWindow() only requests to terminate the process.
Other useful functions to control the exiting process: WaitForExit() , Exited event etc.
-obislavu-
 
You say that I'll only be able to do this on the local machine, which is exactly what I can't do. I need to do this remotely. Do you by any chance know which of the msi classes I can use to close the application and update it?

The way the architecture works is that we have about 1500 remote pc's running this application which all needs to be updated on a specified time, whether the user is working on it or not. If the user is working on it though I want to display a message that the app will close in 5 minutes and then stop it after that period and start the update automatically.

Any ideas?
 
For that task there are already some packages. One is NetWizard which includes more than you want.
But, if you want to implement something to control a given application remotely the approach is to develop a kind of agent to be deployed on 1500 machines.
Firts , you should broadcast a message informing the end user for 5 minutes of remaining time.
Next , you send a message to all 1500 agents to stop the application if the end user didn't it.
This agent serach on that machine the process by name or by id and force it to terminate using Kill() ore CloseMainWindow().
The agent could be also running as a service on each of 1500 machines.
When you want to install a new release on that machine , send a message to that service from where to download the installer files (on a given machine or a and it will do the work and send you back a message when done.
A way to talk a remote service to perform some tasks dynamically is to notify it by updating its .exe.config file. In this case the service has a thread that watches the .exe.config file.
So, your app will modify that file (1500 files), perform tasks and could send back to your app when tasks ate done.
As you can see , you delegate most of work to a service running on the each 1500 machines.
Use Process, System.Net.Sockets, TcpClient, Socket classes to accomplish these tasks.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top