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.
Solutions
- Run BetterGI as a normal interactive Windows user account that has a user SID.
- Confirm via `whoami /user` that the account exposes a user SID.
- 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
- Run BetterGI as an interactive Windows user with a valid SID.
- Confirm the account exposes a user SID via `whoami /user`.
- Do not launch BetterGI from service contexts that strip the user token.
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
- 无法取得当前 Windows 用户 SID。
- 文件路径 ' ' 包含非法字符
- 当前 Windows 未提供任务计划程序 COM 服务。
- 游戏窗口分辨率不是 16:9
- 游戏窗口分辨率不是 16:9 !无法使用地图追踪功能!
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/22b25d7fc2fbc11a.
Report an issue: GitHub.
Appendix: 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)