windows2003 终端服务管理器

使用 wtsapi32.dll 提供的 函数

//---------------------------------------------------------------------------
char* __fastcall Tfm_LoginList::GetWTSString(DWORD sID,WTS_INFO_CLASS wtsInfo)
{
        LPTSTR p = NULL;
        DWORD  bufCount;
        char* Result = NULL;
        if(WTSQuerySessionInformation(0,sID,wtsInfo,&p,&bufCount))
        {
                Result = new char[bufCount];
                strcpy(Result,p);
        }
        else
                Result = "<Unknown>";
        WTSFreeMemory(p);
        return  Result;

}
// 将获得的客户端显示在一个 listview 中
void __fastcall Tfm_LoginList::btnRefClick(TObject *Sender)
{

      PWTS_SESSION_INFO   pSession,   pWTS_Info;
      DWORD   sID,SessionCount; 
      char   uName[50]; //用户名称
      String   wName;
      int   i,sState; 
      DWORD   bufCount,ProcessCount;
      TCHAR     *p=NULL;
      HANDLE hServer = 0;
      TListItem *pItem;
  

      ListView1->Clear();
      if(WTSEnumerateSessions(hServer,0,1,&pSession,&SessionCount))
      {
        pWTS_Info=pSession; 
        for(   i   =   0;   i<SessionCount;   i++)
        {
            sID   =   pSession->SessionId;
            pItem = ListView1->Items->Add();
            pItem->Caption = sID;  
            pItem->SubItems->Add(GetWTSString(sID,WTSUserName));
            pItem->SubItems->Add(GetWTSString(sID,WTSClientName)) ;
           
            WTS_CLIENT_ADDRESS *ip = NULL;
            if(WTSQuerySessionInformation(hServer,sID,WTSClientAddress,(LPTSTR *)&ip,&bufCount))
            {
                char* cAddress = new char[bufCount];
                memset( cAddress,0,bufCount);
                sprintf(cAddress, "%d.%d.%d.%d",ip->Address[2],ip->Address[3],ip->Address[4],ip->Address[5]);
                pItem->SubItems->Add(cAddress);
                WTSFreeMemory(ip);
                delete  cAddress;
            }

            pSession++;
        }
        }

}

 

//断开选中的 客户端连接
//---------------------------------------------------------------------------
void __fastcall Tfm_LoginList::btnlogoffClick(TObject *Sender)
{
    if(ListView1->Items->Count > 0)
    {
       int pos = ListView1->ItemIndex;
       TListItem* pItem = ListView1->Items->Item[pos];
       String seid = pItem->Caption;
       if(WTSLogoffSession(0,seid.ToInt(),true))
       {
        pItem->Delete();
       }
    }
}
//---------------------------------------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值