diff --git a/NewLife.Agent/Windows/Desktop.cs b/NewLife.Agent/Windows/Desktop.cs index d2b8054..1cbc826 100644 --- a/NewLife.Agent/Windows/Desktop.cs +++ b/NewLife.Agent/Windows/Desktop.cs @@ -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)); @@ -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); } } }