现在的位置: 首页 > 综合 > 正文

windows NT中获取系统用户名

2013年03月25日 ⁄ 综合 ⁄ 共 10101字 ⁄ 字号 评论关闭
文章目录

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

Wtsapi32.h

Library

Wtsapi32.lib

DLL

Wtsapi32.dll

Unicode and ANSI names

WTSQuerySessionInformationW (Unicode)>

Constants

WTSInitialProgram

A>Note  Despite>Window Stations.

WTSDomainName

A null-terminated string that contains the name of the domain to which the logged-on user belongs.

WTSConnectState

The session's current connection state. For more information, seeWTS_CONNECTSTATE_CLASS.

WTSClientBuildNumber

A ULONG value>WTSClientName

A null-terminated string that contains the name of the client.

WTSClientDirectory

A null-terminated string that contains the directory in which the client is installed.

WTSClientProductId

A USHORT client-specific>WTSClientHardwareId

A ULONG value that contains a client-specific hardware identifier. This option is reserved for future use. WTSQuerySessionInformation will>WTSClientAddress

The network type and network address of the client. For more information, seeWTS_CLIENT_ADDRESS.

The IP address is offset by two bytes from the start of the Address member of theWTS_CLIENT_ADDRESS structure.

WTSClientDisplay

Information about the display resolution of the client. For more information, seeWTS_CLIENT_DISPLAY.

WTSClientProtocolType

A USHORT value>ValueMeaning

0

The console session.

1

This value is retained for legacy purposes.

2

The RDP protocol.

 

WTSIdleTime

This value returns FALSE. If>GetLastError to get extended error information,GetLastError returns ERROR_NOT_SUPPORTED.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSLogonTime

This value returns FALSE. If>GetLastError to get extended error information,GetLastError returns ERROR_NOT_SUPPORTED.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSIncomingBytes

This value returns FALSE. If>GetLastError to get extended error information,GetLastError returns ERROR_NOT_SUPPORTED.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSOutgoingBytes

This value returns FALSE. If>GetLastError to get extended error information,GetLastError returns ERROR_NOT_SUPPORTED.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSIncomingFrames

This value returns FALSE. If>GetLastError to get extended error information,GetLastError returns ERROR_NOT_SUPPORTED.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSOutgoingFrames

This value returns FALSE. If>GetLastError to get extended error information,GetLastError returns ERROR_NOT_SUPPORTED.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSClientInfo

Information about a Remote Desktop Connection (RDC) client. For more information, seeWTSCLIENT.

Windows Vista, Windows Server 2003,>WTSSessionInfo

Information about a client session on an RD Session Host server. For more information, seeWTSINFO.

Windows Vista, Windows Server 2003,>WTSSessionInfoEx

Extended information about a session on an RD Session Host server. For more information, see WTSINFOEX.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSConfigInfo

Information about the configuration of an RD Session Host server.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSValidationInfo

This value is not supported.

WTSSessionAddressV4

A WTS_SESSION_ADDRESS structure that contains the IPv4 address assigned to the session. If the session does not have a virtual IP address, theWTSQuerySessionInformation function
returns ERROR_NOT_SUPPORTED.

Windows Server 2008, Windows Vista, Windows Server 2003,>WTSIsRemoteSession

Determines whether the current session is a remote session. TheWTSQuerySessionInformation function returns a value of TRUE to indicate that the current session is a remote session,
and FALSE to indicate that the current session is a local session. This value can only be used for the local machine, so the hServer parameter of the WTSQuerySessionInformation function
must containWTS_CURRENT_SERVER_HANDLE.

Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:  This value is not supported.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Wtsapi32.h






更多


查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场


    个人资料

    • 访问:31672次
    • 积分:1361分
    • 排名:第8859名
    • 原创:17篇
    • 转载:555篇
    • 译文:0篇
    • 评论:11条
    推荐文章

      最新评论

    抱歉!评论已关闭.