Nikhil Gaur
Nikhil Gaur

Reputation: 1272

Creating Automatic application updater in C#

I have a windows application (lets say it "App A") which contains some windows services and a window form.

Now I am creating another application (name it "App B") which contains a windows service. This will check on my server if a newer version of "App A" is available or not. If newer version is available it will

download the new version --> uninstall the "App A" --> install new version

For uninstall I am using this code :

private void uninstall()
    {
        Process p = new Process();
        p.StartInfo.FileName = "C:\\WINDOWS\\system32\\msiexec.exe";
        p.StartInfo.Arguments = "/x \"c:\\AppA.msi\" /qn";
        p.Start();
        p.WaitForExit();
    }

For install I am using this code :

private void install()
    {
        Process p = new Process();
        p.StartInfo.FileName = "C:\\WINDOWS\\system32\\msiexec.exe";
        p.StartInfo.Arguments = "/i \"c:\\AppA.msi\" /qn";
        p.Start();
        p.WaitForExit();
    }

But this code is not working and application is not uninstalled.

Please tell me if I am doing anything wrong. Its really very urgent.

Upvotes: 1

Views: 816

Answers (1)

SmithMart
SmithMart

Reputation: 2801

To help troubleshoot why this is happening i would do 2 things, first change the uninstall code to:

private void uninstall()
{
    Process p = new Process();
        p.StartInfo.FileName = @"C:\WINDOWS\system32\msiexec.exe";
        p.StartInfo.Arguments = @"C:\Windows\System32\MSIEXEC.EXE /l* ""AppAUninstall.log"" /q /norestart /x""C:\MyApp.msi""";
        p.Start();
        p.WaitForExit();
}

This code will leave a file called AppAUninstall.log which will tell you the output of the msi uninstall, this could have info as to why its not uninstalling

Also, you have the quiet argument, /q, on there. Most of the time an MSI will need to be elevated with UAC on windows vista and above when run, so if you're updater application is not running as administrator then this will quietly fail.

Martyn

Upvotes: 1

Related Questions