/// <inheritdoc />
        public bool TryElevate(ElevationAction elevationAction, string reason)
        {
            if (reason == null)
            {
                throw new ArgumentNullException("reason");
            }
            if (elevationAction == null)
            {
                throw new ArgumentNullException("elevationAction");
            }

            if (HasElevatedPrivileges)
            {
                var elevationContext = new LocalElevationContext(runtime);
                return(elevationAction(elevationContext));
            }

            try
            {
                using (IHost host = CreateHost())
                {
                    var elevationContext = new HostedElevationContext(host);
                    if (!elevationContext.Initialize(runtime.GetRuntimeSetup(), runtime.Logger))
                    {
                        return(false);
                    }

                    return(elevationAction(elevationContext));
                }
            }
            catch (Exception ex)
            {
                runtime.Logger.Log(LogSeverity.Error, "Failed to create an elevation context out of process.", ex);
                return(false);
            }
        }
        /// <inheritdoc />
        public bool TryElevate(ElevationAction elevationAction, string reason)
        {
            if (reason == null)
                throw new ArgumentNullException("reason");
            if (elevationAction == null)
                throw new ArgumentNullException("elevationAction");

            if (HasElevatedPrivileges)
            {
                var elevationContext = new LocalElevationContext(runtime);
                return elevationAction(elevationContext);
            }

            try
            {
                using (IHost host = CreateHost())
                {
                    var elevationContext = new HostedElevationContext(host);
                    if (!elevationContext.Initialize(runtime.GetRuntimeSetup(), runtime.Logger))
                        return false;

                    return elevationAction(elevationContext);
                }
            }
            catch (Exception ex)
            {
                runtime.Logger.Log(LogSeverity.Error, "Failed to create an elevation context out of process.", ex);
                return false;
            }
        }