Strange return from WTSOpenServerA

Todd Chester 646 Reputation points
2022-11-30T01:13:43.633+00:00

With the following call

C++
HANDLE WTSOpenServerA(
[in] LPSTR pServerName
);
Return value: ... the return value is a handle to the specified server. If the function fails, it returns a handle that is not valid.

I am getting back a different number each time I run it. For instance:

650254464
1395857536
3414144

Are these the invalid numbers referred to above?

What does a good number look like?

And what is this referring to"You can test the validity of the handle by using it in another function call."?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 40,286 Reputation points
    2022-11-30T02:45:37.067+00:00

    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.

    Note that unlike some other Windows API functions where a failure will return a NULL handle or a handle containing INVALID_HANDLE_VALUE the documentation for WTSOpenServerA does not give a value to identify an invalid handle if the function fails. So the only way to know if you have received a valid handle is to use it in another function call and be sure to test whether that call succeeds or fails.

    You should treat the server handle as an opaque value. The numeric representation of a server handle will appear differently between a 32-bit process and a 64-bit process. Multiple executions of a process that calls WTSOpenServerA successfully will not always obtain the same server handle.


0 additional answers

Sort by: Most helpful