windows NT中获取系统用户名

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

C++
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

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

USHORT client-specific>WTSClientHardwareId

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值