我正在Windows服务中使用以下c#代码捕获远程连接和断开事件。
我如何获得远程连接到该计算机的最终用户的IP地址。
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
switch (changeDescription.Reason)
{
case SessionChangeReason.RemoteConnect:
//Remote Connect
break;
case SessionChangeReason.RemoteDisconnect:
//Remote Disconnect
break;
default:
break;
}
}
[我在c#中找到了相关的解决方案,它使用PInvoke WTSQuerySessionInformation
和WTS_INFO_CLASS.WTSClientAddress
有关更多详细信息,您可以转到此处:Grabbing Information of a Terminal Services Session Programmatically