babalae/better-genshin-impact · error · InvalidOperationException

当前 Windows 未提供任务计划程序 COM 服务。

Error message

当前 Windows 未提供任务计划程序 COM 服务。

What it means

Thrown when Type.GetTypeFromProgID("Schedule.Service") returns null — the Task Scheduler COM automation object is not registered or not available on this Windows installation. The Child Session elevated-launch path relies on Task Scheduler to start a process in a specific session with high privileges.

Source

Thrown at BetterGenshinImpact/Service/ChildSession/ChildSessionProcessLauncher.cs:103

    }

    private static void LaunchWithTemporaryTask(
        uint childSessionId,
        string executablePath,
        string arguments,
        string workingDirectory)
    {
        var actualChildSessionId = ChildSessionNativeMethods.TryGetChildSessionId();
        if (actualChildSessionId != childSessionId)
        {
            throw new InvalidOperationException(
                $"目标 Child Session 已发生变化。请求会话为 {childSessionId},当前会话为 "
                + (actualChildSessionId?.ToString(CultureInfo.InvariantCulture) ?? "无")
                + "。");
        }

        var schedulerType = Type.GetTypeFromProgID("Schedule.Service")
            ?? throw new InvalidOperationException("当前 Windows 未提供任务计划程序 COM 服务。");
        var taskName = $"BetterGI-ChildSession-ElevatedLaunch-{Guid.NewGuid():N}";
        string accountName;
        using (var currentIdentity = WindowsIdentity.GetCurrent())
        {
            accountName = currentIdentity.Name;
        }

        object? schedulerObject = null;
        object? rootFolderObject = null;
        object? taskDefinitionObject = null;
        object? actionObject = null;
        object? registeredTaskObject = null;
        object? runningTaskObject = null;
        var taskRegistered = false;

        try
        {
            schedulerObject = Activator.CreateInstance(schedulerType)

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Run BetterGI on a full desktop Windows edition (Home/Pro/Enterprise) where the Task Scheduler service is present and running.
  2. Enable the Task Scheduler service: set its startup type to Automatic and start it via services.msc or `sc config Schedule start= auto`.
  3. If a debloat tool removed the COM registration, repair Windows or re-register the Task Scheduler COM components.
  4. Note that Child Session elevated launch is not supported on Server Core by design.
Defensive patterns

Strategy: validation

Validate before calling

// Probe for Task Scheduler availability before attempting an elevated launch.
if (Type.GetTypeFromProgID("Schedule.Service") is null)
{
    throw new InvalidOperationException("当前 Windows 未提供任务计划程序 COM 服务。");
}

Try / catch

try
{
    await ChildSessionProcessLauncher.LaunchElevatedAsync(childSessionId, exePath);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("任务计划程序"))
{
    // Inform the user the OS edition does not support Child Session elevated launch.
    logger.LogError(ex, "Task Scheduler COM unavailable");
}

Prevention

When it happens

Trigger: Running BetterGI on a Windows edition where the Task Scheduler service is disabled, removed, or its COM registration is missing (Server Core, locked-down LTSC, Group Policy disabling the Schedule service, or a broken COM registry).

Common situations: Windows Server Core without Desktop Experience; enterprise Group Policy that disables the Task Scheduler service; a Windows image stripped by a debloat tool that removed schtasks/COM registration.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/0e33543551c77939. Report an issue: GitHub.