Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I launch msiexec in another process and wait for exit:

var p = new Process
{
    StartInfo =
    {
        FileName = "msiexec",
        Arguments = string.Format("/i "{0}" /qb", @"c:installsetup.msi"),
        Verb = "runas"
    }
};
p.Start();
p.WaitForExit();
int exitCode = p.ExitCode;

If the setup.msi has not been previously installed it is installing to silent mode and returns 0. It normal.

But if setup.msi already installed (launch this code second time), installation not starting and return code 0 - success result! But in fact, the files have not been established, because product is already installed. How I can determine this situation?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
377 views
Welcome To Ask or Share your Answers For Others

1 Answer

You received an exit code of 0 because the product is already installed and you are not attempting to install a new version. In otherwords, your MSI does not have a new Product Code and version number, therefore the MSIExec installer considers it a reconfiguration, and exits. I tested this out by turning on the /log switch and reading the output after installing one of my MSI files twice.

MSI (c) (98:EC) [15:19:27:912]: Product: Product Name -- Configuration completed successfully. MSI (c) (98:EC) [15:19:27:912]: Windows Installer reconfigured the product. Product Name: Product Name. Product Version: 4.8.22. Product Language: 1033. Manufacturer: Manufacturer. Reconfiguration success or error status: 0.

If you were trying to install a new version of your product and your MSI was not configured to remove previous versions, you would receive an error code of 1638. See list of error codes here: MSDN

If you want to check if the product is already installed with the existing MSI information (not an upgrade) you would need to check the registry at: HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstallYourProductCode

If it turns out it is installed (according to the system/registry -- maybe the files were deleted but it still is considered to be installed) you can try uninstalling it using the /x or /uninstall switch and then reinstalling. You could also use the /fa switch to do a repair and reinstall all files.

msiexec.exe /x ProductCode will uninstall it. Then you can run the install again after that. msiexec.exe /fa ProductCode will do a repair of all files. The /f switch has a lot of different options for how it reinstalls files, so you'd do well to read the link to the msiexec switches article I posted above.

Some other notes about msiexec:

/qb displays a basic user interface. You probably want /qn. When I was setting up my live-update software I ran into a bunch of problems, I had to make sure I called msiexec from system32 by using

p.StartInfo.FileName == Path.Combine(System.Environment.ExpandEnvironmentVariables("%windir%\system32"), "MSIExec.exe"); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...