private void AutomationThread()
        {
            try
            {
                AutomatedUninstallManager.UninstallNsisQuietly(UninstallTarget, AutomatizeStatusCallback);

                OnStatusUpdate(new UninstallHandlerUpdateArgs(UninstallHandlerUpdateKind.Succeeded, Localization.Message_Success));
            }
            catch (AutomatedUninstallManager.AutomatedUninstallException ex)
            {
                Debug.Assert(ex.InnerException != null, "ex.InnerException != null");

                OnStatusUpdate(new UninstallHandlerUpdateArgs(UninstallHandlerUpdateKind.Failed, string.Format(Localization.Message_UninstallFailed, ex.InnerException?.Message ?? ex.Message)));

                // todo grace period / move to window?
                if (ex.UninstallerProcess != null && KillOnFail)
                {
                    try
                    {
                        ex.UninstallerProcess.Kill(true);
                    }
                    catch
                    {
                        // Ignore process errors, can't do anything about it
                    }
                }

                Program.ReturnValue = ReturnValue.FunctionFailedCode;
            }
        }
        private static int Main(string[] args)
        {
            try { Console.OutputEncoding = Encoding.Unicode; }
            catch (IOException) { /*Old .NET v4 without support for unicode output*/ }

            if (args.Length < 2)
            {
                return(InvalidArgumentCode);
            }

            UninstallerType uType;

            if (!Enum.TryParse(args[0], out uType))
            {
                return(InvalidArgumentCode);
            }

            args = args.Skip(1).ToArray();

            if (args[0].Equals("/k", StringComparison.InvariantCultureIgnoreCase))
            {
                args        = args.Skip(1).ToArray();
                _killOnFail = true;
            }

            try
            {
                if (uType == UninstallerType.Nsis)
                {
                    var cline = string.Join(" ", args);
                    Console.WriteLine(@"Automatically uninstalling " + cline);
                    AutomatedUninstallManager.UninstallNsisQuietly(cline);
                    return(OkCode);
                }
            }
            catch (AutomatedUninstallManager.AutomatedUninstallException ex)
            {
                Console.WriteLine(@"Automatic uninstallation failed");
                Console.WriteLine(@"Reason: " + ex.InnerException.Message);

                if (ex.UninstallerProcess != null && _killOnFail)
                {
                    try
                    {
                        ex.UninstallerProcess.Kill(true);
                    }
                    catch
                    {
                        // Ignore process errors, can't do anything about it
                    }
                }

                return(FunctionFailedCode);
            }

            Console.WriteLine(uType + @" is not supported");
            return(InvalidArgumentCode);
        }