babalae/better-genshin-impact · error · InvalidOperationException

无法取得当前 Windows 用户 SID。

Error message

无法取得当前 Windows 用户 SID。

What it means

Thrown by InstancePipeNames.ForCurrentUser when WindowsIdentity.GetCurrent().User is null — the per-user pipe name is derived from the user SID, so without one the name cannot be constructed. This runs early, during InstanceBootstrap.Initialize, before any pipe is created.

Source

Thrown at BetterGenshinImpact/Service/Instance/InstanceContext.cs:79

{
    public BetterGiInstanceType InstanceType { get; init; }

    public int ProcessId { get; init; }

    public int WindowsSessionId { get; init; }

    public DateTimeOffset StartedAt { get; init; }
}

internal static class InstancePipeNames
{
    private const string Prefix = "BetterGI.v2.user-";

    internal static string ForCurrentUser()
    {
        using var identity = WindowsIdentity.GetCurrent();
        var userSid = identity.User
                      ?? throw new InvalidOperationException("无法取得当前 Windows 用户 SID。");
        return ForUserSid(userSid.Value);
    }

    internal static string ForUserSid(string userSid)
    {
        return $"{Prefix}{userSid}.root";
    }
}

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Run BetterGI as a normal interactive Windows user account that has a user SID.
  2. Confirm via `whoami /user` that the account exposes a user SID.
  3. Avoid launching BetterGI from contexts that strip the user token (e.g. some task scheduler service accounts).
Defensive patterns

Strategy: validation

Validate before calling

using var identity = WindowsIdentity.GetCurrent();
var userSid = identity.User ?? throw new InvalidOperationException("无法取得当前 Windows 用户 SID。");
var pipeName = InstancePipeNames.ForUserSid(userSid.Value);

Try / catch

try
{
    var rootPipeName = InstancePipeNames.ForCurrentUser();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("SID"))
{
    logger.LogCritical(ex, "No user SID at bootstrap; use an interactive Windows account");
}

Prevention

When it happens

Trigger: Same as 471: the process runs under an account with no user SID. ForCurrentUser() is called at bootstrap to compute the root pipe name for the current user.

Common situations: BetterGI launched from a service/automation account lacking a user SID; sandboxed or virtualized Windows where the identity has no user SID.

Related errors


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