Windows API 23 篇 WTSQuerySessionInformation
Posted prairieNew
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows API 23 篇 WTSQuerySessionInformation相关的知识,希望对你有一定的参考价值。
函数原型:
BOOL
WINAPI
WTSQuerySessionInformationW(
IN HANDLE hServer,
IN DWORD SessionId,
IN WTS_INFO_CLASS WTSInfoClass,
__deref_out_bcount(*pBytesReturned) LPWSTR * ppBuffer,
__out DWORD * pBytesReturned
);
说明:
hServer: WTS_CURRENT_SERVER_HANDLE
SessionId:会话ID,可以从WTSEnumerateProcesses或者WTSEnumerateSessions 或WTSGetActiveConsoleSessionId
中得到,
WTSInfoClass:指定要查找的信息,该结构是一个枚举类型,可以看下面定义:
typedef enum _WTS_INFO_CLASS {
WTSInitialProgram,
WTSApplicationName,
WTSWorkingDirectory,
WTSOEMId,
WTSSessionId,
WTSUserName,
WTSWinStationName,
WTSDomainName,
WTSConnectState,
WTSClientBuildNumber,
WTSClientName,
WTSClientDirectory,
WTSClientProductId,
WTSClientHardwareId,
WTSClientAddress,
WTSClientDisplay,
WTSClientProtocolType
} WTS_INFO_CLASS;
ppBuffer:输出指针
pBytesReturned:返回信息的长度
DWORD dwSessionId = WTSGetActiveConsoleSessionId(); PVOID pstr = NULL; DWORD dwLen = 0; WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, dwSessionId, WTS_INFO_CLASS::WTSUserName, (LPWSTR*)&pstr, &dwLen); wstring strUserName = (PWCHAR)pstr;
以上是关于Windows API 23 篇 WTSQuerySessionInformation的主要内容,如果未能解决你的问题,请参考以下文章
一脚踩进java之基础篇23——常用API(ObjectString)
windows API 第22篇 WTSGetActiveConsoleSessionId
Windows API 第17篇 GetLogicalDriveStrings 获取本机所有逻辑驱动器,以根目录的形式表示