【问题标题】:Programly detect if my machine remotely accessed程序检测我的机器是否远程访问
【发布时间】:2013-08-16 08:31:47
【问题描述】:

我在一台 PC 上运行了一个 winservice,它连接到服务器,因此我们可以将命令推送到这个 winservcice。

其中一个命令应该是:isConnectedRemotly:如果有人从其他机器(远程)连接到这台机器,它应该返回 true,并且对于哪个用户名(它连接到的会话用户名)

我该怎么做?

【问题讨论】:

    标签: windows winapi wmi remote-access wtsapi32


    【解决方案1】:

    这取决于...如果您的意思是“调用进程是否在远程会话下运行,您可以通过obtain the session id for the processget info for the session 来检查它是否是远程会话,例如:

    DWORD ProcessId; // filled by the calling program using GetCurrentProcessId()
    DWORD SessionId, ByteCount;
    LPTSTR Buffer;
    if (ProcessIdToSessionId(ProcessId, &SessionId))
        if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, SessionId,
                                       WTSIsRemoteSession, &Buffer, &ByteCount))
            if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, SessionId,
                                           WTSUserName, &Buffer, &ByteCount))
            {   // copy away the user name in Buffer
                WTSFreeMemory(Buffer);
            }
    

    【讨论】:

    • 为什么需要第二个“WTSQuerySessionInformation”调用(WTSUserName)?,不,我想知道:“用户名是否登录到远程会话”
    • 第一次调用WTSQuerySessionInformation() 参数-3 = WTSIsRemoteSession 确定用户是否登录到远程会话,第二次调用检索用户名(WTSUserName
    猜你喜欢
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    相关资源
    最近更新 更多