• Windowns API 第24篇 WTSEnumerateSessions 枚举session信息


    函数原型:
    BOOL WTSEnumerateSessions(  HANDLE hServer,
                                                          DWORD Reserved, 
                                                          DWORD Version,
                                                          PWTS_SESSION_INFO* ppSessionInfo, 
                                                          DWORD* pCount
                                                        );
    作用:对当前系统的session信息进行枚举。
    参数说明:
    hServer:指定要对终端断服务枚举的句柄,本机可以的话可以为WTS_CURRENT_SERVER_HANDLE, 或者NULL
    Reserved:系统保留位,必须为0
    Version:指定枚举请求的版本,必须为1
    ppSessionInfo:一个WTS_SESSION_INFO结构
    可以看一下该结构的定义:
    typedef struct _WTS_SESSION_INFO
    {   
         DWORD SessionId;  
         LPTSTR pWinStationName;
         WTS_CONNECTSTATE_CLASS State;
     } WTS_SESSION_INFO, * PWTS_SESSION_INFO;
    
    该结构中包含绘画ID, Windows空间站名,session的状态,此状态为枚举值。再次看下一结构
    typedef enum _WTS_CONNECTSTATE_CLASS
    {
        WTSActive,              // User logged on to WinStation
        WTSConnected,           // WinStation connected to client
        WTSConnectQuery,        // In the process of connecting to client
        WTSShadow,              // Shadowing another WinStation
        WTSDisconnected,        // WinStation logged on without client
        WTSIdle,                // Waiting for client to connect
        WTSListen,              // WinStation is listening for connection
        WTSReset,               // WinStation is being reset
        WTSDown,                // WinStation is down due to error
        WTSInit,                // WinStation in initialization
    } WTS_CONNECTSTATE_CLASS;
    
    
    pCount:返回Session的数量,为输出参数
    
    举例说明:
    
       void main()
    
       {
    
            PWTS_SESSION_INFO psi;
    	DWORD dwCount;
    
    	BOOL bRet = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &psi, &dwCount);
    
    	if (!bRet)
    		return 0;
    	wstring strName;
    	for (unsigned int i = 0; i < dwCount; i ++)
    	{
    		printf("%s 	", psi[i].pWinStationName);
    		printf("%d 	", psi[i].SessionId);
    		printf("%d 
    ", psi[i].State);
    	}
    	WTSFreeMemory(psi);
    
        }
    
  • 相关阅读:
    64位操作系统Visual Studio连接本机oracle的问题
    解决Oracle启动失败
    通过应用程序域AppDomain加载和卸载程序集
    C#应用程序实现单例模式
    不实现 INotifyPropertyChanged接口也能实现数据绑定
    WPF弹出“选择文件夹”对话框
    Linux常用命令
    markedown基本语法
    git使用
    用户打开浏览器,输入buidu.com页面展示百度首页。整个过程发生了什么?
  • 原文地址:https://www.cnblogs.com/priarieNew/p/9755679.html
Copyright © 2020-2023  润新知