【发布时间】:2017-11-22 12:32:39
【问题描述】:
我的计划 Windows 服务在系统中运行。在其中,我想检测同一系统中的特定用户是否远程断开连接。
为了实现这一点,目前我正在重写 System.ServiceProcess.ServiceBase 类的 OnSessionChange(..) 方法以将状态写入文件以及何时写入 我需要检查状态,我从同一个文件中读取它。
但我想知道一种更好的检测方法而不将其存储在文件中?
class mySessionBase : ServiceBase
{
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
//Save the status of machine in file
hangeDescription.Reason.ToString()
changeDescription.SessionId
}
}
是否有任何窗口远程 API 可用于检测相同的?
提前致谢
马亨
【问题讨论】:
-
查看
WTSEnumerateSessions()和WTSQuerySessionInformation()。您可以从后者检索用户信息和远程状态 -
是的,WTSEnumerateSessions() 对我们有用
标签: c# winapi windows-services window remote-desktop