Discussion:
WTSSendMessageA handle?
(too old to reply)
T
2022-11-19 07:55:40 UTC
Permalink
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
2022-11-19 09:19:34 UTC
Permalink
Post by T
Hi All,
Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
   [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
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.
JJ
2022-11-19 09:24:38 UTC
Permalink
Post by T
Hi All,
Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
[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
It's there in the text you just posted.
T
2022-11-19 09:30:04 UTC
Permalink
Post by JJ
Post by T
Hi All,
Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
[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
It's there in the text you just posted.
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
2022-11-19 11:41:27 UTC
Permalink
Post by T
Post by JJ
Post by T
Hi All,
Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
[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
It's there in the text you just posted.
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
`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
2022-11-19 23:45:06 UTC
Permalink
Post by JJ
Post by T
Post by JJ
Post by T
Hi All,
Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
[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
It's there in the text you just posted.
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
`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.
What is the difference between GetComputerName and

C++

int gethostname(
[out] char *name,
[in] int namelen
);
T
2022-11-20 05:35:49 UTC
Permalink
Post by T
Post by JJ
Post by T
Post by JJ
Post by T
Hi All,
Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
      [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
It's there in the text you just posted.
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
`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.
What is the difference between GetComputerName and
C++
int gethostname(
  [out] char *name,
  [in]  int  namelen
);
Trivia. I just noticed that "
T
2022-11-20 06:08:31 UTC
Permalink
Post by T
Post by JJ
Post by T
Post by JJ
Post by T
Hi All,
Windows 11-pro 22H2
https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
      [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
It's there in the text you just posted.
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
`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.
What is the difference between GetComputerName and
C++
int gethostname(
   [out] char *name,
   [in]  int  namelen
);
Trivia.  I just noticed that "[out] char *name,"
is in UTF16 format.
Oops.
JJ
2022-11-20 14:07:01 UTC
Permalink
Post by T
What is the difference between GetComputerName and
C++
int gethostname(
   [out] char *name,
   [in]  int  namelen
);
Trivia.  I just noticed that "[out] char *name,"
is in UTF16 format.
Oops. My bad. It is utf8
"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
2022-11-20 21:19:09 UTC
Permalink
Post by JJ
Post by T
What is the difference between GetComputerName and
C++
int gethostname(
   [out] char *name,
   [in]  int  namelen
);
Trivia.  I just noticed that "[out] char *name,"
is in UTF16 format.
Oops. My bad. It is utf8
"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`.
WTSSendMessageA states:

[in] hServer

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

So which of
JJ
2022-11-21 01:23:59 UTC
Permalink
Post by T
[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
2022-11-21 11:27:09 UTC
Permalink
Post by JJ
Post by T
[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.
Thank you!

Loading...