/// <summary> /// Installs the specified MSI. /// </summary> /// <param name="packagePath">The full path to the MSI package.</param> /// <param name="logFile">The full path of the log file.</param> /// <returns>An error code indicating the result of the operation.</returns> protected uint InstallMsi(string packagePath, string logFile) { // Make sure the package we're going to run is coming from the cache. if (!packagePath.StartsWith(Cache.PackageCacheRoot)) { return(Error.INSTALL_PACKAGE_INVALID); } Elevate(); if (IsElevated) { ConfigureInstall(logFile); return(WindowsInstaller.InstallProduct(packagePath, s_installProperties)); } else if (IsClient) { InstallResponseMessage response = Dispatcher.SendMsiRequest(InstallRequestType.InstallMsi, logFile, packagePath); ExitOnFailure(response, "Failed to install MSI."); return(response.Error); } throw new InvalidOperationException($"Invalid configuration: elevated: {IsElevated}, client: {IsClient}"); }
/// <summary> /// Throws an exception if the HRESULT of the response message indicates /// a failure. /// </summary> /// <param name="response">The response message to examine.</param> /// <exception cref="WorkloadException"/> protected void ExitOnFailure(InstallResponseMessage response, string message) { if (response.HResult < 0) { throw new WorkloadException(string.IsNullOrWhiteSpace(message) ? response.Message : $"{message} {response.Message}", response.HResult); } }
/// <summary> /// Repairs the specified MSI package. /// </summary> /// <param name="productCode">The product code of the MSI to repair.</param> /// <param name="logFile">The full path of the log file.</param> /// <returns>An error code indicating the result of the operation.</returns> protected uint RepairMsi(string productCode, string logFile) { Elevate(); if (IsElevated) { ConfigureInstall(logFile); return(WindowsInstaller.ReinstallProduct(productCode, DefaultReinstallMode)); } else if (IsClient) { InstallResponseMessage response = Dispatcher.SendMsiRequest(InstallRequestType.RepairMsi, logFile, null, productCode); ExitOnFailure(response, "Failed to repair MSI."); return(response.Error); } throw new InvalidOperationException($"Invalid configuration: elevated: {IsElevated}, client: {IsClient}"); }
/// <summary> /// Uninstalls the MSI using its provided product code. /// </summary> /// <param name="productCode">The product code of the MSI to uninstall.</param> /// <param name="logFile">The full path of the log file.</param> /// <returns>An error code indicating the result of the operation.</returns> protected uint UninstallMsi(string productCode, string logFile) { Elevate(); if (IsElevated) { ConfigureInstall(logFile); return(WindowsInstaller.ConfigureProduct(productCode, WindowsInstaller.INSTALLLEVEL_DEFAULT, InstallState.ABSENT, s_uninstallProperties)); } else if (IsClient) { InstallResponseMessage response = Dispatcher.SendMsiRequest(InstallRequestType.UninstallMsi, logFile, null, productCode); ExitOnFailure(response, "Failed to uninstall MSI."); return(response.Error); } throw new InvalidOperationException($"Invalid configuration: elevated: {IsElevated}, client: {IsClient}"); }
public void Reply(InstallResponseMessage message) { WriteMessage(message.ToByteArray()); }
/// <summary> /// Sends a message and blocks until a reply is received. /// </summary> /// <param name="message">The message to send.</param> /// <returns>The response message.</returns> public InstallResponseMessage Send(InstallRequestMessage message) { WriteMessage(message.ToByteArray()); return(InstallResponseMessage.Create(ReadMessage())); }