This topic has not yet been rated - Rate this topic

WTSOpenServer function

Applies to: desktop apps only

Opens a handle to the specified Remote Desktop Session Host (RD Session Host) server.

Syntax

HANDLE WTSOpenServer(
  __in  LPTSTR pServerName
);

Parameters

pServerName [in]

Pointer to a null-terminated string specifying the NetBIOS name of the RD Session Host server.

Return value

If the function succeeds, the return value is a handle to the specified server.

If the function fails, it returns a handle that is not valid. You can test the validity of the handle by using it in another function call.

Windows Server 2003, Windows XP, and Windows 2000:  If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

When you have finished using the handle returned by WTSOpenServer, release it by calling the WTSCloseServer function.

You do not need to open a handle for operations performed on the RD Session Host server on which your application is running. Use the constant WTS_CURRENT_SERVER_HANDLE instead.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Wtsapi32.h

Library

Wtsapi32.lib

DLL

Wtsapi32.dll

Unicode and ANSI names

WTSOpenServerW (Unicode) and WTSOpenServerA (ANSI)

See also

WTSCloseServer

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
"You can test the validity of the handle by using it in another function call"
You should provide an WTSIsHandleValid API if this the design. However, why isn't the code returning NULL or INVALID_HANDLE as all other Win32 API?
Must provide Netbios name only
If you include the leading backslashes to the computer name, ie \\dummy, the function will provide a valid handle, but attempting to use it will fail with various non-helpful errors.
always succeeds on Vista
If you call WTSOpenServer on Windows Vista/2008 the call will always succeed and always returns a handle.
Example:

hServer = WTSOpenServer("DUMMY")

below Vista this returns null/0 but on Vista a valid handle (to local session manager) is returned.

In Windows 7 this seems to have been resolved.