0

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

Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34
AMDI
  • 895
  • 2
  • 17
  • 40
  • What do you mean with 'uninstalling .exe files' ? Give some examples which kind of programs you CAN uninstall and which you don't. – Alex H Oct 12 '15 at 14:14

2 Answers2

1

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.

Maximilian Gerhardt
  • 5,188
  • 3
  • 28
  • 61
0

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

Community
  • 1
  • 1
Hayha
  • 2,144
  • 1
  • 15
  • 27
  • Please, add the main points of the article to your answer. That way information will be on SO even if the original article is moved/deleted. Thanks. – Dethariel Oct 12 '15 at 14:30