Hi guys, 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?
Hi guys, 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?
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.
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.
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();
}
}
Yes using System.Diagnostics
You can get the process and Kill the Process.
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();