void HandleUri(string Uri)
        {
            try
            {
                UriResult Result = UriHandler.HandleUri(Uri);
                if (!Result.Success)
                {
                    if (!string.IsNullOrEmpty(Result.Error))
                    {
                        MessageBox.Show(String.Format("Error handling uri: {0}", Result.Error));
                    }

                    return;
                }

                if (Result.Request != null)
                {
                    PostRequest(Result.Request);
                    Result.Request.Complete.Wait();
                    Result.Request.Dispose();
                }
            }
            catch { }
        }
        /// <summary>
        /// Handle URI passed in via command lines
        /// </summary>
        public static bool ProcessCommandLine(string[] Args, bool FirstInstance, EventWaitHandle ActivateEvent = null)
        {
            if (Args.Any(x => x.Equals(InstallHandlerArg, StringComparison.OrdinalIgnoreCase)))
            {
                if (Args.Any(x => x.Equals(ElevatedArg, StringComparison.OrdinalIgnoreCase)))
                {
                    ProtocolHandlerUtils.InstallElevated();
                }
                else
                {
                    ProtocolHandlerUtils.Install();
                }
                return(true);
            }
            else if (Args.Any(x => x.Equals(UninstallHandlerArg, StringComparison.OrdinalIgnoreCase)))
            {
                if (Args.Any(x => x.Equals(ElevatedArg, StringComparison.OrdinalIgnoreCase)))
                {
                    ProtocolHandlerUtils.UninstallElevated();
                }
                else
                {
                    ProtocolHandlerUtils.Uninstall();
                }
                return(true);
            }
            else
            {
                string UriIn = string.Empty;
                for (int Idx = 0; Idx < Args.Length; Idx++)
                {
                    const string Prefix = "-uri=";
                    if (Args[Idx].StartsWith(Prefix, StringComparison.OrdinalIgnoreCase))
                    {
                        UriIn = Args[Idx].Substring(Prefix.Length);
                    }
                }

                if (UriIn == string.Empty)
                {
                    return(false);
                }

                Uri Uri;
                try
                {
                    Uri = new Uri(UriIn);
                }
                catch
                {
                    MessageBox.Show(String.Format("Invalid URI: {0}", UriIn));
                    return(true);
                }

                MethodInfo Handler;
                if (!Handlers.TryGetValue(Uri.Host, out Handler))
                {
                    MessageBox.Show(String.Format("Unknown action from URI request ('{0}')", Uri.Host));
                    return(true);
                }

                UriHandlerAttribute Attribute = Handler.GetCustomAttribute <UriHandlerAttribute>();

                // handle case where we terminate after invoking handler
                if (Attribute.Terminate)
                {
                    UriResult Result = HandleUri(UriIn);
                    if (!Result.Success)
                    {
                        MessageBox.Show(Result.Error);
                    }
                    return(true);
                }

                if (!FirstInstance)
                {
                    if (ActivateEvent != null)
                    {
                        ActivateEvent.Set();
                    }

                    // send to main UGS process using IPC
                    AutomationServer.SendUri(UriIn);
                    return(true);
                }

                // we're in the main UGS process, which was also launched, defer handling to after main window is created
                return(false);
            }
        }