peass-ng/PEASS-ng · error · InvalidOperationException

The current task is no longer running.

Error message

The current task is no longer running.

What it means

RunningTask.Refresh throws InvalidOperationException when the underlying v2 running-task COM object reports the task is no longer running. It means the task finished or was stopped between obtaining the RunningTask and calling Refresh, leaving the COM handle stale; the exception is documented on Refresh for exactly this lifecycle condition.

Source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs:1014

        /// <summary>Gets the operational state of the running task.</summary>
        public override TaskState State => v2RunningTask?.State ?? base.State;

        /// <summary>Releases all resources used by this class.</summary>
        public new void Dispose()
        {
            base.Dispose();
            if (v2RunningTask != null) Marshal.ReleaseComObject(v2RunningTask);
        }

        /// <summary>Refreshes all of the local instance variables of the task.</summary>
        /// <exception cref="InvalidOperationException">Thrown if task is no longer running.</exception>
        public void Refresh()
        {
            try { v2RunningTask?.Refresh(); }
            catch (COMException ce) when ((uint)ce.ErrorCode == 0x8004130B)
            {
                throw new InvalidOperationException("The current task is no longer running.", ce);
            }
        }
    }

    /// <summary>
    /// Provides the methods that are used to run the task immediately, get any running instances of the task, get or set the credentials
    /// that are used to register the task, and the properties that describe the task.
    /// </summary>
    [XmlType(IncludeInSchema = false)]
    [PublicAPI]
    public class Task : IDisposable, IComparable, IComparable<Task>, INotifyPropertyChanged
    {
        internal const AccessControlSections defaultAccessControlSections = AccessControlSections.Owner | AccessControlSections.Group | AccessControlSections.Access;
        internal const SecurityInfos defaultSecurityInfosSections = SecurityInfos.Owner | SecurityInfos.Group | SecurityInfos.DiscretionaryAcl;
        internal ITask v1Task;

        private static readonly int osLibMinorVer = GetOSLibraryMinorVersion();
        private static readonly DateTime v2InvalidDate = new DateTime(1899, 12, 30);

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Check the task's State before calling Refresh and skip the call when it is not Running.
  2. Catch InvalidOperationException around Refresh and treat it as task completion.
  3. Re-acquire a fresh RunningTask via Task.Run/TaskService.GetTask instead of refreshing a stale instance.
  4. Dispose the stale RunningTask after handling the exception to release the COM object.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs:1014 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/671e1ec8474916ca. Report an issue: GitHub.