KinesisTapMsiCustomAction/CustomAction.cs
/// <summary>
/// Upgrade from Powershell installed KinesisTap. Detect if the KinesisTap is installed via Powershell, if it is, stop the service and remove powershell registers.
/// </summary>
/// <param name="session"></param>
/// <returns></returns>
Upgrade from Powershell installed KinesisTap. Detect if the KinesisTap is installed via Powershell, if it is, stop the service and remove powershell registers.
Upgrade from Powershell installed KinesisTap . Detect if the KinesisTap is installed via Powershell if it is stop the service and remove powershell registers .
[CustomAction]
        public static ActionResult UpgradePowershellInstalledKinesisTap(Session session)
        {
            session.Log("Begin upgrading Powershell installed KinesisTap");
            string serviceName = session.CustomActionData["SERVICENAME"];
            RegistryKey registryKeyHKLM = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            string keyPath = $@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{serviceName}";
            try
            {
                RegistryKey key = registryKeyHKLM.OpenSubKey(keyPath, true);
                string valueData;
                if (key != null && (valueData = (string)key.GetValue("UninstallString")) != null)
                {
                    if (valueData.Contains("uninstall.ps1"))
                    {
                        session.Log($@"KinesisTap found is PowerShell installed.");
                        ServiceController kinesistapService = ServiceController.GetServices()
                            .FirstOrDefault(s => s.ServiceName == serviceName);
                        if (kinesistapService == null)
                        {
                            session.Log("KinesisTap service is not installed.");
                        }
                        else
                        {
                            session.Log("KinesisTap service is installed.");
                            if (kinesistapService.CanStop)
                            {
                                session.Log("KinesisTap service is running. Terminating...");
                                kinesistapService.Stop();
                            }
                        }
                        session.Log($@"Deleting registry 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{serviceName}'.");
                        key.Close();
                        registryKeyHKLM.DeleteSubKeyTree(keyPath);
                    }
                }
            }
            catch (Exception ex)
            {
                session.Log($"Failed to upgrade from Powershell installed KinesisTap: {ex.Message}");
                return ActionResult.Failure;
            }
            finally
            {
                registryKeyHKLM.Close();
            }
            session.Log("Finish upgrading Powershell installed KinesisTap");
            return ActionResult.Success;
        }
[ CustomAction ] public static ActionResult UpgradePowershellInstalledKinesisTap ( Session session ) { session . Log ( " " ) ; string serviceName = session . CustomActionData [ " " ] ; RegistryKey registryKeyHKLM = RegistryKey . OpenBaseKey ( RegistryHive . LocalMachine , RegistryView . Registry64 ) ; string keyPath = $@" SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ { serviceName } " ; try { RegistryKey key = registryKeyHKLM . OpenSubKey ( keyPath , true ) ; string valueData ; if ( key != null && ( valueData = ( string ) key . GetValue ( " " ) ) != null ) { if ( valueData . Contains ( " " ) ) { session . Log ( $@" KinesisTap found is PowerShell installed. " ) ; ServiceController kinesistapService = ServiceController . GetServices ( ) . FirstOrDefault ( s => s . ServiceName == serviceName ) ; if ( kinesistapService == null ) { session . Log ( " " ) ; } else { session . Log ( " " ) ; if ( kinesistapService . CanStop ) { session . Log ( " " ) ; kinesistapService . Stop ( ) ; } } session . Log ( $@" Deleting registry 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ { serviceName } '. " ) ; key . Close ( ) ; registryKeyHKLM . DeleteSubKeyTree ( keyPath ) ; } } } catch ( Exception ex ) { session . Log ( $" Failed to upgrade from Powershell installed KinesisTap:  { ex . Message } " ) ; return ActionResult . Failure ; } finally { registryKeyHKLM . Close ( ) ; } session . Log ( " " ) ; return ActionResult . Success ; }
Upgrade from Powershell installed KinesisTap.
Upgrade from Powershell installed KinesisTap .
//Need to run UpgradePowershellInstalledKinesisTap.SetProperty custom action first to set the value // KinesisTap is PowerShell installed, delete the registery key // Stop KinesisTap service if it is running
None
session
Session
None