1

I have created a C# Windows Form that uses WTSRegisterSessionNotification to Register for Remote Desktop session notifications. Then I am handling the WM_WTSSESSION_CHANGE message in WndProc callback function. The issue I am having is that I want to achieve the same functionality as a Windows Service.

When I tried the following in a Windows Service project Result = False.

var result = WTSRegisterSessionNotification(Process.GetCurrentProcess().MainWindowHandle, 1);

So I cant even register the notification. Can someone point me in the right direction?

Sean Marraffa
  • 432
  • 5
  • 12
  • 1
    Services run in their own world, in session 0. No interactive users run in session 0. WM_WTSSESSION_CHANGE is a window message (i.e., something a window receives). Services don't have windows. That message is also about a change in the session - which is necessarily a different session that what the service is running in. What you are trying to do will not work (as far as I know). So... What do you really want to do? Be notified when a user logs in or out? Something else? There may be a way to do what you wan that will work. – Flydog57 Aug 21 '18 at 20:39
  • I need a way to be notified that a user logs in and out. – Sean Marraffa Aug 21 '18 at 20:44
  • This seems harder than I thought it would be... Try looking at this: https://stackoverflow.com/questions/16282231/get-notified-from-logon-and-logoff – Flydog57 Aug 21 '18 at 20:56

0 Answers0