Fix: Modern Terminal blank under SYSTEM; precise reason in info list
This commit is contained in:
@@ -136,6 +136,35 @@ inline bool IsTerminalModuleLoaded()
|
||||
return g_hTerminalModule != nullptr;
|
||||
}
|
||||
|
||||
// Check if current process is running as LocalSystem (S-1-5-18).
|
||||
// 用途:WebView2 / msedgewebview2.exe 子进程拒绝在 SYSTEM token 下渲染(Microsoft
|
||||
// 官方限制),此时 Modern Terminal 会打开但页面空白,需要回退到经典终端。
|
||||
// 结果缓存,因为进程 token 在生命周期内不会变。
|
||||
inline bool IsRunningAsSystem()
|
||||
{
|
||||
static int cached = -1;
|
||||
if (cached >= 0) return cached == 1;
|
||||
|
||||
bool isSystem = false;
|
||||
HANDLE hToken = nullptr;
|
||||
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
|
||||
BYTE buf[256] = {};
|
||||
DWORD len = 0;
|
||||
if (GetTokenInformation(hToken, TokenUser, buf, sizeof(buf), &len)) {
|
||||
SID_IDENTIFIER_AUTHORITY ntAuth = SECURITY_NT_AUTHORITY;
|
||||
PSID pSystemSid = nullptr;
|
||||
if (AllocateAndInitializeSid(&ntAuth, 1, SECURITY_LOCAL_SYSTEM_RID,
|
||||
0, 0, 0, 0, 0, 0, 0, &pSystemSid)) {
|
||||
isSystem = EqualSid(((TOKEN_USER*)buf)->User.Sid, pSystemSid) != FALSE;
|
||||
FreeSid(pSystemSid);
|
||||
}
|
||||
}
|
||||
CloseHandle(hToken);
|
||||
}
|
||||
cached = isSystem ? 1 : 0;
|
||||
return isSystem;
|
||||
}
|
||||
|
||||
// Check if WebView2 Runtime is installed (cached)
|
||||
inline bool IsWebView2Available()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user