CeccoCQ
CeccoCQ

Reputation: 3754

Close windows application

is it possible to close a running application with another application?

I have implemented APP1.exe and APP1_UNIN.exe, I would that APP1_UNIN.exe kill running APP1.exe and uninstall it. Is it possible?

Upvotes: 1

Views: 1267

Answers (5)

slugster
slugster

Reputation: 49985

To uninstall an application, you can start a new process and invoke msiexec.exe, and on the command line you can specify what to uninstall:

ProcessStartInfo psi;
//take your choice of which you want to use:
psi = new ProcessStartInfo("msiexec.exe", string.Format("/x {0}", "path of my msi"));
psi = new ProcessStartInfo("msiexec.exe", string.Format("/x /n {{{0}}}", "my product code"));
Process p = new Process();
p.StartInfo = psi;
p.Start();

Upvotes: 1

Hemant Kumar
Hemant Kumar

Reputation: 4611

Yes using System.Diagnostics

You can get the process and Kill the Process.

Upvotes: 0

Ruel
Ruel

Reputation: 15780

For closing, you can do it by killing its process. System.Diagnostics.Process

Process []pArray = Process.GetProcesses();

foreach(Process prc in pArray) {
    string s = prc.ProcessName;
    if (s.CompareTo("APP1") ==0) {
        prc.Kill();
    }
}

Upvotes: 0

Øyvind Bråthen
Øyvind Bråthen

Reputation: 60724

At least to kill the running process you can do like this:

Process[] processes = Process.GetProcesses();
foreach (Process process in processes) {
  if (process.ProcessName == "APP1.exe") {
    try {
      process.Kill();
      break;
      } catch (Exception) { 
        //handle any exception here
      }
    }
  }
}

Regarding uninstalling it, I'm not sure.

Upvotes: 1

Jakub Konecki
Jakub Konecki

Reputation: 46008

Use System.Diagnostics.Process class:

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.closemainwindow(v=VS.71).aspx

There's also a Kill method.

Upvotes: 1

Related Questions