Make WinVNC service mode work on Windows Vista and beyond.
Patch by Jochen Tucht, fixes bug 135.



git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5158 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/win/winvnc/VNCServerWin32.cxx b/win/winvnc/VNCServerWin32.cxx
index 4d89a0e..9d77c27 100644
--- a/win/winvnc/VNCServerWin32.cxx
+++ b/win/winvnc/VNCServerWin32.cxx
@@ -55,6 +55,8 @@
 VNCServerWin32::VNCServerWin32()
   : command(NoCommand), commandSig(commandLock),
     commandEvent(CreateEvent(0, TRUE, FALSE, 0)),
+    sessionEvent(isServiceProcess() ?
+      CreateEvent(0, FALSE, FALSE, "Global\\SessionEventTigerVNC") : 0),
     vncServer(CStr(ComputerName().buf), &desktop),
     hostThread(0), runServer(false), isDesktopStarted(false),
     httpServer(&vncServer), config(&sockMgr), trayIcon(0),
@@ -72,6 +74,8 @@
 
   // Register the queued command event to be handled
   sockMgr.addEvent(commandEvent, this);
+  if (sessionEvent)
+    sockMgr.addEvent(sessionEvent, this);
 }
 
 VNCServerWin32::~VNCServerWin32() {
@@ -322,6 +326,8 @@
       command = NoCommand;
       commandSig.signal();
     }
+  } else if (event_ == sessionEvent.h) {
+    stop();
   }
 }