BOOL CSecurityTool::GetLogUserXP(CString& strName)
{
BOOL bRet = FALSE;
strName = _T("");
//for xp or above
TCHAR *szLogName = NULL;
DWORD dwSize = 0;
if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
WTS_CURRENT_SESSION,
WTSUserName,
&szLogName,
&dwSize))
{
strName = szLogName;
WTSFreeMemory(szLogName);
bRet = TRUE;
}
return bRet;
}
//-------------------------------------------------------------------------------
http://msdn.microsoft.com/en-us/library/aa383838(VS.85).aspx
Retrieves session information for the specified session on the specified Remote Desktop Session Host (RD Session Host) server. It can be used to query session information on local and remote RD Session Host servers.
Syntax
BOOL WTSQuerySessionInformation( _In_ HANDLE hServer, _In_ DWORD SessionId, _In_ WTS_INFO_CLASS WTSInfoClass, _Out_ LPTSTR *ppBuffer, _Out_ DWORD *pBytesReturned );
Parameters
-
hServer
[in]
-
A handle to an RD Session Host server. Specify a handle opened by the WTSOpenServerfunction, or specify WTS_CURRENT_SERVER_HANDLE to indicate the RD Session Host server on which your application is running.
SessionId
[in]
-
A Remote Desktop Services session identifier. To indicate the session in which the calling application is running (or the current session) specify WTS_CURRENT_SESSION. Only specify WTS_CURRENT_SESSION when obtaining session information on the local server. IfWTS_CURRENT_SESSION is specified when querying session information on a remote server, the returned session information will be inconsistent. Do not use the returned data.
You can use the WTSEnumerateSessions function to retrieve the identifiers of all sessions on a specified RD Session Host server.
To query information for another user's session, you must have Query Information permission. For more information, see Remote Desktop Services Permissions. To modify permissions on a session, use the Remote Desktop Services Configuration administrative tool.
WTSInfoClass
[in]
-
A value of the WTS_INFO_CLASS enumeration that indicates the type of session information to retrieve in a call to the WTSQuerySessionInformation function.
ppBuffer
[out]
-
A pointer to a variable that receives a pointer to the requested information. The format and contents of the data depend on the information class specified in the WTSInfoClassparameter. To>WTSFreeMemory function.
pBytesReturned
[out]
-
A pointer to a variable that receives the size, in bytes, of the data returned in ppBuffer.
Return value
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero. To get extended error information, callGetLastError.
Remarks
To retrieve the session ID for the current session when Remote Desktop Services is running, callWTSQuerySessionInformation and>ProcessIdToSessionId function.
To determine whether your application is running on the physical console, you must specifyWTS_CURRENT_SESSION for the SessionId parameter, and WTSClientProtocolType as theWTSInfoClass parameter. If ppBuffer is "0", the session is attached to the physical console.
Requirements
Minimum supported client | Windows XP [desktop apps only] | ||||||
---|---|---|---|---|---|---|---|
Minimum supported server | Windows Server 2003 [desktop apps only] | ||||||
Header |
| ||||||
Library |
| ||||||
DLL |
| ||||||
Unicode and ANSI names | WTSQuerySessionInformationW (Unicode)> Constants
Requirements
|