How to remove software using C # by calling UninstallString software listed in the registry file of this software, but the process does not work

I am developing software that will list all the software installations in the computer. Now I want to remove it using my program in C # calling the delete key for this software in the registry key My program Like this, but the process does not work

var UninstallDir = "MsiExec.exe /I{F98C2FAC-6DFB-43AB-8B99-8F6907589021}"; string _path = ""; string _args = ""; Process _Process = new Process(); if (UninstallDir != null && UninstallDir != "") { if (UninstallDir.StartsWith("rundll32.exe")) { _args = ConstructPath(UninstallDir); _Process.StartInfo.FileName = Environment.SystemDirectory.ToString() + "\\explorer.exe"; _Process.StartInfo.Arguments = Environment.SystemDirectory.ToString() + "\\" + UninstallDir; _Process.Start(); } else if (UninstallDir.StartsWith("MsiExec.exe")) { _args = ConstructPath(UninstallDir); _Process.StartInfo.FileName = Environment.SystemDirectory.ToString() + "\\cmd.exe"; _Process.StartInfo.Arguments = Environment.SystemDirectory.ToString() + "\\" + UninstallDir; _Process.Start(); } else { //string Path = ConstructPath(UninstallDir); _path = ConstructPath(UninstallDir); if (_path.Length > 0) { _Process.StartInfo.FileName = _path; _Process.StartInfo.UseShellExecute = false; _Process.Start(); } } 
+4
source share
3 answers

Try this approach:

  Process p = new Process(); p.StartInfo.FileName = "msiexec.exe"; p.StartInfo.Arguments = "/x {F98C2FAC-6DFB-43AB-8B99-8F6907589021}/qn"; p.Start(); 

Refer to this link: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/msiexec.mspx?mfr=true

NTN.

+2
source

The problem with your misexec.exe code is that running cmd.exe someprogram.exe does not start the program, because cmd.exe does not execute the arguments passed to it. But you can say it with the / C switch, as shown here . In your case, this should work:

  _Process.StartInfo.FileName = Environment.SystemDirectory.ToString() + "\\cmd.exe"; _Process.StartInfo.Arguments = "/C " + Environment.SystemDirectory.ToString() + "\\" + UninstallDir; 

Where all I did was add /C (with a space after) to the beginning of the arguments. However, I do not know how to make your rundll32.exe code work.

+1
source

Your solution looks good, but keep a space before \qn :

 p.StartInfo.Arguments = "/x {F98C2FAC-6DFB-43AB-8B99-8F6907589021} /qn"; 

Otherwise, it will not operate in silent mode.

0
source

Source: https://habr.com/ru/post/1394567/


All Articles