I am planning to uninstall .exe files from control panel using c#.
i am able to remove .msi files,but facing issue while trying to remove .exe files.
Can anyone please suggest if there is any different way to remove .exe files.
Thanks in advance
I am planning to uninstall .exe files from control panel using c#.
i am able to remove .msi files,but facing issue while trying to remove .exe files.
Can anyone please suggest if there is any different way to remove .exe files.
Thanks in advance
First of all, you probably don't mean to "remove" an .exe file, by the means of just deleting it from the harddrive with a System.IO.File.Delete()
call. You may want to call the appropiate uninstalling program for each program installed on the computer, in which case you'll find the appropiate directories and paths in the registry, as instructed in this answer.
You can use the msiexec.exe to manage .msi and .exe files
Firstable, we are going to use System.Diagnostics, so you will have to add this.
using System.Diagnostics;
The code to install software without user interface is:
private void installSoftware()
{
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/i \"C:\\Application.msi\"/qn";
p.Start();
}
The code to uninstall software without user interface is:
private void uninstallSoftware()
{
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/x \"C:\\Application.msi\"/qn";
p.Start();
}
The code to repair software without user interface is:
private void repairSoftware()
{
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/f \"C:\\Application.msi\"/qn";
p.Start();
}
Ressource : http://www.codeproject.com/Articles/20059/C-Installing-and-uninstalling-software
To use it with .exe file, simply change the path of your .msi file by the product code of your application
private void uninstallSoftware()
{
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/x "ProductCode" /qn";
p.Start();
}
To know more about how to get a product code of an application you can see this answer: How to find the upgrade code & productCode of an installed application in Win 7