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();
        }
    }

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.