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/rfb_win32/LaunchProcess.cxx b/win/rfb_win32/LaunchProcess.cxx
index 56a712e..16ced64 100644
--- a/win/rfb_win32/LaunchProcess.cxx
+++ b/win/rfb_win32/LaunchProcess.cxx
@@ -44,10 +44,20 @@
   await();
   returnCode = STILL_ACTIVE;
 
+  DWORD size;
+  char desktopName[256];
+  char buf[256];
+  HDESK desktop = GetThreadDesktop(GetCurrentThreadId());
+  if (!GetUserObjectInformation(desktop, UOI_NAME, buf, 256, &size))
+    throw rdr::SystemException("unable to launch process", GetLastError());
+
+  snprintf(desktopName, 256, "WinSta0\\%s", buf);
+
   // - Create storage for the process startup information
   STARTUPINFO sinfo;
   memset(&sinfo, 0, sizeof(sinfo));
   sinfo.cb = sizeof(sinfo);
+  sinfo.lpDesktop = desktopName;
 
   // - Concoct a suitable command-line
   TCharArray exePath;
diff --git a/win/rfb_win32/Service.cxx b/win/rfb_win32/Service.cxx
index 982a5b3..89be92e 100644
--- a/win/rfb_win32/Service.cxx
+++ b/win/rfb_win32/Service.cxx
@@ -40,6 +40,7 @@
 // - Internal service implementation functions
 
 Service* service = 0;
+bool runAsService = false;
 
 VOID WINAPI serviceHandler(DWORD control) {
   switch (control) {
@@ -323,6 +324,13 @@
   if (!osVersion.isPlatformNT)
     return false;
 
+  if (osVersion.dwMajorVersion >= 6) {
+    rfb::win32::Handle sessionEventCad = 
+      CreateEvent(0, FALSE, FALSE, "Global\\SessionEventTigerVNCCad");
+    SetEvent(sessionEventCad);
+    return true;
+  }
+
   CADThread* cad_thread = new CADThread();
   vlog.debug("emulate Ctrl-Alt-Del");
   if (cad_thread) {
@@ -641,5 +649,5 @@
 
 
 bool rfb::win32::isServiceProcess() {
-  return service != 0;
+  return runAsService;
 }