Skip to content

Commit

Permalink
[fix]修正win10+net9无法在后台服务创建前台进程的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 16, 2024
1 parent 666c523 commit 68f6ffc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions NewLife.Agent/Windows/Desktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ private static UInt32 GetFirstActiveSessionOfEnumerateSessions()
var arrayElementSize = Marshal.SizeOf(typeof(WtsSessionInfo));
var current = pSessionInfo;

/*
* 常见会话:
* 0, Services, WTSDisconnected
* 1, Console, WTSActive
* 2, "", WTSDisconnected -YiFan
* 3, "", WTSDisconnected -YiFei
* 65536, 31C5CE94259D4006A9E4, WTSListen
* 65537, RDP-Tcp, WTSListen
*/
for (var i = 0; i < sessionCount; i++)
{
var si = (WtsSessionInfo)Marshal.PtrToStructure(current, typeof(WtsSessionInfo));
Expand All @@ -308,9 +317,8 @@ private static UInt32 GetFirstActiveSessionOfEnumerateSessions()
// 清理资源
if (pSessionInfo != IntPtr.Zero)
{
WTSFreeMemory(pSessionInfo);
//如果没有判断是否为IntPtr.Zero,会导致引发SEHException异常:"external component has thrown an exception"
CloseHandle(pSessionInfo);
WTSFreeMemory(pSessionInfo);
}
}
}
Expand Down

0 comments on commit 68f6ffc

Please sign in to comment.