babalae/better-genshin-impact · error · InvalidOperationException
无法取得当前 Windows 用户 SID。
Error message
无法取得当前 Windows 用户 SID。
What it means
Thrown by InstancePipeFactory.CreateServer when WindowsIdentity.GetCurrent().User is null — the current security principal has no user SID, so the named pipe ACL cannot be scoped to the current user (the pipe security denies network access and grants the owner full control, both keyed off the SID).
Source
Thrown at BetterGenshinImpact/Service/Instance/InstanceBootstrap.cs:286
return null;
}
}
return null;
}
}
internal sealed record InitialRootConnection(
NamedPipeClientStream Client,
ConnectionOpenResponse Response);
internal static class InstancePipeFactory
{
internal static NamedPipeServerStream CreateServer(string pipeName, bool firstPipeInstance)
{
using var identity = WindowsIdentity.GetCurrent();
var ownerSid = identity.User
?? throw new InvalidOperationException("无法取得当前 Windows 用户 SID。");
var networkSid = new SecurityIdentifier(WellKnownSidType.NetworkSid, null);
var security = new PipeSecurity();
security.SetAccessRuleProtection(isProtected: true, preserveInheritance: false);
security.SetOwner(ownerSid);
security.AddAccessRule(new PipeAccessRule(
networkSid,
PipeAccessRights.FullControl,
AccessControlType.Deny));
security.AddAccessRule(new PipeAccessRule(
ownerSid,
PipeAccessRights.FullControl,
AccessControlType.Allow));
var options = PipeOptions.Asynchronous | PipeOptions.WriteThrough;
if (firstPipeInstance)
{
options |= PipeOptions.FirstPipeInstance;
}
View on GitHub (pinned to a7cb36712d)
Solutions
- Run BetterGI as a normal interactive Windows user account (the same account used for the desktop session).
- Verify the account has a valid user SID via `whoami /user` — it must list an SID.
- If running in automation, use an account with a real user SID rather than SYSTEM-without-profile.
Defensive patterns
Strategy: validation
Validate before calling
using var identity = WindowsIdentity.GetCurrent();
if (identity.User is null)
{
throw new InvalidOperationException("无法取得当前 Windows 用户 SID。");
} Try / catch
try
{
var server = InstancePipeFactory.CreateServer(pipeName, firstPipeInstance: true);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("SID"))
{
logger.LogCritical(ex, "No user SID; run BetterGI as an interactive Windows user");
} Prevention
- Run BetterGI as a normal interactive Windows user account that has a user SID.
- Verify the account with `whoami /user` before automating launches.
- Avoid service accounts whose tokens lack a user SID.
When it happens
Trigger: Running BetterGI under an account whose WindowsIdentity.User is null: certain service accounts, anonymous/low-privilege sandboxes, or environments where the user token has no user SID (e.g. some containerized or virtualized Windows hosts).
Common situations: BetterGI launched from a service context or a non-interactive account; a broken user profile; running under a custom principal that does not map to a Windows user SID.
Related errors
- 无法取得当前 Windows 用户 SID。
- 文件路径 '{path}' 包含非法字符
- 当前 Windows 未提供任务计划程序 COM 服务。
- 同一个 BvFlow 不能并发执行
- BvFlow 第 {i + 1} 步执行失败:{step.Description}
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/4cbd504aeddb5708.
Report an issue: GitHub.