1

I'm writing a simple system service to switch on and off the remote desktop access of some computers depending on a schedule. This includes notifying, then logging off remote users that would be connected when the system switches to local-only.

To notify the user, I'm using the WTSSendMessage function, which can display a dialog box inside a given session. It also allows specifying a timeout—which is very important in this case so that if nobody acknowledges the message within a given timeout, the service can simply force the logoff.

The problem I'm facing is that WTSSendMessage (at least on the latest Windows 10, version 2004, and on Windows Server 2019 version 1809, the two systems on which I tested) doesn't return IDTIMEOUT properly when the dialog box only has the OK button:

WTSSendMessage(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, SESSION_STOP_TITLE,
  strlen(SESSION_STOP_TITLE), SESSION_STOP_MSG, strlen(SESSION_STOP_MSG), 
  MB_OK | MB_ICONEXCLAMATION, SESSION_WARNING_TIMEOUT, &resp, TRUE);

In this case, the resp variable always contains IDOK, independently on whether the user clicks OK or the timeout expires. The documentation doesn't say anything about a special case with a single OK button.

If instead of MB_OK I use anything else (e.g., MB_YESNO), the call properly works and resp will contain either IDYES, IDNO, or IDTIMEOUT depending on what happened. I also tried explicitly using the unicode (WTSSendMessageW) version of the function just in case, but it doesn't change anything.

Is this a bug within the terminal services API? I didn't find any references to this behaviour anywhere. Would there be a workaround (besides rephrasing the message and using a Yes/No or OK/Cancel boutton couple)?

Ale
  • 1,727
  • 14
  • 26
  • "*Is this a bug within the terminal services API?*" - sounds like it. It is certainly different behavior than what is documented. File a bug report with Microsoft. – Remy Lebeau Aug 27 '20 at 17:42
  • @RemyLebeau Do you have an idea where to file such a bug? I tried looking around on Microsoft's web site, but couldn't really find a place to report bugs in APIs... There's a related answer (https://stackoverflow.com/a/276493/1931985) but MS Connect "has been retired"... – Ale Aug 28 '20 at 08:26
  • 1
    Another answer on the same question: https://stackoverflow.com/a/276131/65863 "*There is no official way to report bugs to Microsoft for an end-user.*" :-( – Remy Lebeau Aug 28 '20 at 08:31

0 Answers0