--- src/emacs.c.orig    2003-08-08 19:32:49.000000000 +0300
+++ src/emacs.c 2003-08-14 15:17:17.000000000 +0300
@@ -1229,8 +1229,48 @@
       }
 #endif
 #ifdef HAVE_MS_WINDOWS
-      if (strcmp(display_use, "x") != 0)
-       display_use = "mswindows";
+      if (strcmp(display_use, "tty") == 0)
+        {
+          /* Check if the process is executing within
+             the interactive window station.
+             This check is only applicable on
+             Windows NT product line (WinNT, Win2k, WinXP) */
+          DWORD dwVersion = GetVersion();
+          if (dwVersion < 0x80000000) /* Are we runnging WinNT ? */
+            {
+              HMODULE hDLL = GetModuleHandle("User32.dll");
+              if (hDLL)
+                {
+                  typedef HWINSTA (WINAPI *GetProcessWindowStationProc)(void);
+                  typedef BOOL (WINAPI *GetUserObjectInformationProc)(HANDLE hObj, int nIndex, PVOID pvInfo, DWORD nLength, LPDWORD lpnLengthNeeded);
+                  GetProcessWindowStationProc pGetProcessWindowStationProc;
+                  GetUserObjectInformationProc pGetUserObjectInformationProc;
+
+                  pGetProcessWindowStationProc = (GetProcessWindowStationProc) GetProcAddress(hDLL, "GetProcessWindowStation");
+                  pGetUserObjectInformationProc = (GetUserObjectInformationProc) GetProcAddress(hDLL, "GetUserObjectInformationA");
+                  if (pGetProcessWindowStationProc && pGetUserObjectInformationProc)
+                    {
+                      HWINSTA hWindowStation = (*pGetProcessWindowStationProc)();
+                      if (hWindowStation != NULL)
+                      {
+                        char strBuffer[100];
+                        DWORD nSize;
+                        if ((*pGetUserObjectInformationProc)(hWindowStation,
+                                                             UOI_NAME,
+                                                             strBuffer,
+                                                             sizeof(strBuffer),
+                                                             &nSize))
+                          if (strcmp(strBuffer, "WinSta0") == 0)
+                            display_use = "mswindows";
+                      }
+                    }
+                }
+            }
+          else
+            {
+              display_use = "mswindows";
+            }
+        }
 #endif /* HAVE_MS_WINDOWS */
     }
 #endif /* HAVE_WINDOW_SYSTEM */