Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
[WinStationQueryInformationW is not supported and may be altered or unavailable in the future. Instead, use the GetSystemMetrics function with SM_REMOTESESSION to obtain this information (see Detecting the Remote Desktop Services Environment). ]
Applies to: desktop apps only
Determines whether the calling application is running on a Remote Desktop Connection (RDC) client.
This function only works reliably on Windows 2000.
BOOLEAN WinStationQueryInformationW(
_In_ HANDLE hServer,
_In_ ULONG LogonId,
_In_ WINSTATIONINFOCLASS WinStationInformationClass,
_Out_ PVOID pWinStationInformation,
_In_ ULONG WinStationInformationLength,
_Out_ PULONG pReturnLength
);
hServer [in]
Must be SERVERNAME_CURRENT.LogonId [in]
Must be LOGONID_CURRENT.WinStationInformationClass [in]
Must be the WinStationInformation value of the WINSTATIONINFOCLASS enumeration.pWinStationInformation [out]
Pointer to a WINSTATIONINFORMATIONW structure to receive return data. Under Windows 2000 only, if WinStationQueryInformationW succeeds and the LogonId element of this structure is nonzero on return, the calling application is running on a Remote Desktop Connection (RDC) client.WinStationInformationLength [in]
Size of the buffer pointed to by the pWinStationInformation parameter. Must be equal to "sizeof(WINSTATIONINFORMATIONW)".pReturnLength [out]
Pointer to a location where the function writes the actual size of the information returned.
Returns TRUE if the function succeeds, or FALSE if not. Additional error information can be obtained on failure by calling GetLastError.
If you do use WinStationQueryInformationW, access the function by Using Run-time Dynamic Linking as shown in the example below. This gives your code an opportunity to respond gracefully if the function has been changed or removed from the operating system. Signature changes, however, may not be detectable.
This function is defined in Winternl.h as follows.
typedef BOOLEAN (WINAPI * PWINSTATIONQUERYINFORMATIONW)(
HANDLE, ULONG, WINSTATIONINFOCLASS, PVOID, ULONG, PULONG );
The entire function below, which uses a call to WinStationQueryInformationW to determine whether it is running on a Remote Desktop Connection (RDC) client, can be replaced by a single call to GetSystemMetrics( SM_REMOTESESSION ).
#include <windows.h>
#include <winternl.h>
BOOL IsRunningOnTerminalServerClient( void )
{
PWINSTATIONQUERYINFORMATIONW WinStationQueryInformationW;
WINSTATIONINFORMATIONW wsInfo;
HINSTANCE hInstWinSta;
ULONG ReturnLen;
hInstWinSta = LoadLibraryA( "winsta.dll" );
if( hInstWinSta )
{
WinStationQueryInformationW = (PWINSTATIONQUERYINFORMATIONW)
GetProcAddress( hInstWinSta, "WinStationQueryInformationW" );
if( WinStationQueryInformationW &&
WinStationQueryInformationW( SERVERNAME_CURRENT,
LOGONID_CURRENT,
WinStationInformation,
&wsInfo,
sizeof(wsInfo),
&ReturnLen ) &&
( wsInfo.LogonId != 0 ) )
{
FreeLibrary( hInstWinSta );
return( TRUE );
}
FreeLibrary( hInstWinSta );
}
return FALSE;
}
Minimum supported client |
Windows 2000 Professional |
Minimum supported server |
Windows 2000 Server |
End of client support |
Windows 2000 Professional |
End of server support |
Windows 2000 Server |
DLL |
Winsta.dll |
Send comments about this topic to Microsoft
Build date: 9/5/2012