VC6中获取远程桌面连接的客户端ip地址

VC6中获取远程桌面连接的客户端ip地址

    在VC6中如果要编译一下代码需要将附件中的文件拷贝到项目目录下。

#include "sal.h"
#include "wtsapi32.h"
#pragma comment(lib, "wtsapi32.lib")
#pragma comment(lib, "kernel32.lib")


#ifdef __cplusplus
extern "C" {
#endif
BOOL WINAPI ProcessIdToSessionId(__in  DWORD dwProcessId,__out DWORD *pSessionId);

#ifdef __cplusplus
}
#endif


#define SM_REMOTESESSION 0x1000


bool GetClientIP(char *clientip)
{
bool fActiveSession = false;
DWORD dwSessionID = -1; // 0 is 1st console session created on XP, 1 is 1st console session on Vista
LPTSTR pData = NULL;
DWORD cbReturned = 0;
WTS_CLIENT_ADDRESS clientaddress;

if(GetSystemMetrics(SM_REMOTESESSION) == 0) return false;


ProcessIdToSessionId(GetCurrentProcessId(), &dwSessionID);
if( WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, dwSessionID, WTSClientAddress, &pData, &cbReturned) && (cbReturned == sizeof(WTS_CLIENT_ADDRESS)) )
{        // if we get WTSActive we're in the active session, otherwise we assume we're not in the active session (WTSDisconnected)
//fActiveSession = (*((INT *)pData) == WTSActive) ? true : false;
memcpy(&clientaddress,pData,sizeof(WTS_CLIENT_ADDRESS));
memset(clientip,0,sizeof(clientip));
sprintf(clientip,"%d.%d.%d.%d", 
clientaddress.Address[2],
clientaddress.Address[3],
clientaddress.Address[4],
clientaddress.Address[5]);
WTSFreeMemory(pData);
return true;
}
WTSFreeMemory(pData);
return false;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值