终端服务会话ID是否可以在进程的生命周期内更改?

时间:2021-05-02 01:41:04

When using .NET's Process.SessionId property or the Windows API call ProcessIdToSessionId(), can the result be relied on to be the same throughout the lifetime of the process?

使用.NET的Process.SessionId属性或Windows API调用ProcessIdToSessionId()时,结果可以在整个过程的生命周期内依赖于相同的结果吗?

i.e. If I want to use this value, do I only have to determine what it is once?

即如果我想使用这个值,我只需要确定它是什么吗?

1 个解决方案

#1


No it's not safe, especially console sessions can change it's sessionid when the connection changes from RDP/remote to the physical console and vice versa or when Fast User Switching is done (Windows XP). Also it wouldn't hurt to call this API often since the SessionId is retreived from the PEB of the process.

不,它不安全,尤其是当连接从RDP / remote更改为物理控制台(反之亦然)或快速用户切换完成时(Windows XP),控制台会话可以更改它的sessionid。此外,通常调用此API也不会有什么坏处,因为SessionId是从进程的PEB中重新获取的。

#1


No it's not safe, especially console sessions can change it's sessionid when the connection changes from RDP/remote to the physical console and vice versa or when Fast User Switching is done (Windows XP). Also it wouldn't hurt to call this API often since the SessionId is retreived from the PEB of the process.

不,它不安全,尤其是当连接从RDP / remote更改为物理控制台(反之亦然)或快速用户切换完成时(Windows XP),控制台会话可以更改它的sessionid。此外,通常调用此API也不会有什么坏处,因为SessionId是从进程的PEB中重新获取的。