WTSSendMessageA handle?

4 views
Skip to first unread message

T

unread,
Nov 19, 2022, 2:55:43 AM11/19/22
to
Hi All,

Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea

WTSSendMessageA states:

[in] hServer

A handle to an RD Session Host server. Specify
a handle opened by the WTSOpenServer function,
or specify WTS_CURRENT_SERVER_HANDLE to indicate
the RD Session Host server on which your application
is running.


If I choose NOT to use "WTS_CURRENT_SERVER_HANDLE",
how to I get my "handle to an RD Session Host server"?

Many thanks,
-T

T

unread,
Nov 19, 2022, 4:21:12 AM11/19/22
to
It is a call to

C++

HANDLE WTSOpenServerA(
[in] LPSTR pServerName
);


But what is the call to get my local computer's
server's name?

I suppose I could always use:

set | grep -i kvm
COMPUTERNAME=KVM-W11
LOGONSERVER=\\KVM-W11

and try to figure out what the format is.
\\ or no \\ etc.

A system call would solve that

JJ

unread,
Nov 19, 2022, 4:24:40 AM11/19/22
to
It's there in the text you just posted.

T

unread,
Nov 19, 2022, 4:30:07 AM11/19/22
to
Hi JJ,

WTS_CURRENT_SERVER_HANDLE is a constant set to 0

I am after the actual handle as I am working in
an RDP environment. It is not zero.

You can get that handle with


C++

HANDLE WTSOpenServerA(
[in] LPSTR pServerName
);


Now all I am missing is the call to get my
local computer's server name (and its syntax)

-T


JJ

unread,
Nov 19, 2022, 6:41:29 AM11/19/22
to
`GetComputerName()` can be used to get the local computer name. But using
that name is same as using `WTS_CURRENT_SERVER_HANDLE`. The local computer
name will always resolve to `127.0.0.1` which is same as `localhost` when
looked up from local computer.

T

unread,
Nov 19, 2022, 6:45:10 PM11/19/22
to
What is the difference between GetComputerName and

C++

int gethostname(
[out] char *name,
[in] int namelen
);


T

unread,
Nov 20, 2022, 12:37:13 AM11/20/22
to
Trivia. I just noticed that "[out] char *name,"
is in UTF16 format.

T

unread,
Nov 20, 2022, 1:09:42 AM11/20/22
to
Oops. My bad. It is utf8

JJ

unread,
Nov 20, 2022, 9:07:04 AM11/20/22
to
"Host name" is not same as "computer name".

`GetComputerName()` returns the computer name as specified in the "System
properties" Control Panel.

`gethostname()` returns the (network) host name as specified in the `HOSTS`
file, which is by default is `localhost`.

T

unread,
Nov 20, 2022, 4:20:20 PM11/20/22
to
WTSSendMessageA states:

[in] hServer

A handle to an RD Session Host server. Specify a
handle opened by the WTSOpenServer function

So which of GetComputerName and gethostname should I use?

JJ

unread,
Nov 20, 2022, 8:24:02 PM11/20/22
to
On Sun, 20 Nov 2022 13:19:09 -0800, T wrote:
>
> WTSSendMessageA states:
>
> [in] hServer
>
> A handle to an RD Session Host server. Specify a
> handle opened by the WTSOpenServer function
>
> So which of GetComputerName and gethostname should I use?

GetComputerName, since Windows networking prioritize NetBIOS name.

T

unread,
Nov 21, 2022, 6:27:12 AM11/21/22
to
Thank you!
Reply all
Reply to author
Forward
0 new messages