4

I am developing a software that will list all the software install in Computer now i want to Uninstall it using my Program In C# by calling the Uninstall Key of that software in Registry Key My Program Is Like That But the Process Is Not Working

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();
        }
    }
Scott Smith
  • 1,703
  • 15
  • 15
Tushar T.
  • 315
  • 2
  • 7
  • 13

3 Answers3

2

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

HTH.

Thinhbk
  • 2,129
  • 21
  • 31
  • This is not enough to construct the path of : msiexec.exe /x {F98C2FAC-6DFB-43AB-8B99-8F6907589021}/qn some time the format if uninstallstring is like: msiexec.exe /I {F98C2FAC-6DFB-43AB-8B99-8F6907589021}/qn – Tushar T. Feb 04 '12 at 05:11
1

The problem with your misexec.exe code is that running cmd.exe someprogram.exe doesn't start the program because cmd.exe doesn't execute arguments passed to it. But, you can tell it to by using the /C switch as seen 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. I don't know how to get your rundll32.exe code to work, however.

Community
  • 1
  • 1
Quantic
  • 1,669
  • 13
  • 25
0

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

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

Otherwise it wont work in silent mode.

will-hart
  • 3,428
  • 1
  • 35
  • 46