delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/06/26/11:15:09

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Fri, 26 Jun 2009 17:14:39 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: popup consoles on Windows 7
Message-ID: <20090626151439.GN30864@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <20090626083640 DOT GF30864 AT calimero DOT vinschen DOT de> <416096c60906260239r5bdaf60bw6a9febe885726f55 AT mail DOT gmail DOT com> <20090626102313 DOT GA12963 AT calimero DOT vinschen DOT de> <416096c60906260503o52ae73ben1140bbbd2db993bb AT mail DOT gmail DOT com> <20090626121215 DOT GJ30864 AT calimero DOT vinschen DOT de> <416096c60906260541t56687113p9c940d4251f68405 AT mail DOT gmail DOT com> <20090626133618 DOT GA14187 AT calimero DOT vinschen DOT de> <af075b00906260708h674121f3s63fdc79af5675a44 AT mail DOT gmail DOT com> <20090626145213 DOT GK30864 AT calimero DOT vinschen DOT de> <20090626150342 DOT GD30070 AT ednor DOT casa DOT cgf DOT cx>
MIME-Version: 1.0
In-Reply-To: <20090626150342.GD30070@ednor.casa.cgf.cx>
User-Agent: Mutt/1.5.19 (2009-02-20)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Jun 26 11:03, Christopher Faylor wrote:
> On Fri, Jun 26, 2009 at 04:52:13PM +0200, Corinna Vinschen wrote:
> >It's an interesting idea, but rather tricky to implement.  I assume
> >you will get an ERROR_ACCESS_DENIED when trying to attach to a console
> >of another user, and a cygserver service would usually run under SYSTEM.
> >Relying on a service at all doesn't sound overly tempting, either.  I'm
> >still hoping for another solution.
> 
> FWIW, I can add another failure point to the mix.  I spent all day one
> Saturday trying to come up with a workaround.  It looks like this is one
> of the many cases where clever Microsoft programmers have worked around
> the clock closing up any loopholes which would allow useful behavior.
> 
> Hmm.  As I was typing this I had another idea which I don't think I
> tried.  I'll look into that this weekend.

I have a local band-aid using AttachConsole and ShowWindowAsync.  If
your idea doesn't work, we could at least use this pathetic workaround.

Index: autoload.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/autoload.cc,v
retrieving revision 1.160
diff -u -p -r1.160 autoload.cc
--- autoload.cc	9 Jun 2009 09:45:29 -0000	1.160
+++ autoload.cc	26 Jun 2009 15:13:48 -0000
@@ -364,6 +364,7 @@ LoadDLLfunc (SendMessageA, 16, user32)
 LoadDLLfunc (SetClipboardData, 8, user32)
 LoadDLLfunc (SetThreadDesktop, 4, user32)
 LoadDLLfunc (SetProcessWindowStation, 4, user32)
+LoadDLLfuncEx (ShowWindowAsync, 8, user32, 1)
 
 LoadDLLfunc (accept, 12, ws2_32)
 LoadDLLfunc (bind, 12, ws2_32)
@@ -408,6 +409,7 @@ LoadDLLfuncEx2 (SendARP, 16, iphlpapi, 1
 
 LoadDLLfunc (CoTaskMemFree, 4, ole32)
 
+LoadDLLfuncEx (AttachConsole, 0, kernel32, 1)
 LoadDLLfuncEx (FindFirstVolumeA, 8, kernel32, 1)
 LoadDLLfuncEx (FindNextVolumeA, 12, kernel32, 1)
 LoadDLLfuncEx (FindVolumeClose, 4, kernel32, 1)
Index: fhandler_console.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_console.cc,v
retrieving revision 1.195
diff -u -p -r1.195 fhandler_console.cc
--- fhandler_console.cc	4 Jun 2009 14:59:47 -0000	1.195
+++ fhandler_console.cc	26 Jun 2009 15:13:48 -0000
@@ -1977,9 +1977,20 @@ fhandler_console::need_invisible ()
 	  debug_printf ("window station is not visible");
 	  invisible_console = true;
 	}
-      else
+      /* BandAid for Windows 7.  AllocConsole is broken on W7 in that it
+         doesn't allocate the console in the hidden, active WindowStation,
+	 but instead on the WindowStation on which the application has
+	 originally been started on.  This effectively disallows to create
+	 a hidden console.
+	 So what we do now is this.  First we try to attach to an existing
+	 console window of the parent process.  If that doesn't work, we
+	 skip generating a hidden WIndowStation entirely.  After creating
+	 the new console, we hide it.  Unfortunately it's still visible in
+	 the taskbar.  Hopefully this will be fixed in SP1... */
+      else if (!wincap.has_broken_alloc_console () || !AttachConsole (-1))
 	{
-	  if (myself->ctty != TTY_CONSOLE)
+	  if (myself->ctty != TTY_CONSOLE
+	      && !wincap.has_broken_alloc_console ())
 	    {
 	      h = CreateWindowStationW (NULL, 0, WINSTA_ACCESS, NULL);
 	      termios_printf ("%p = CreateWindowStation(NULL), %E", h);
@@ -1991,6 +2002,8 @@ fhandler_console::need_invisible ()
 	    }
 	  b = AllocConsole ();	/* will cause flashing if CreateWindowStation
 				   failed */
+	  if (wincap.has_broken_alloc_console ())
+	    ShowWindowAsync (GetConsoleWindow (), SW_HIDE);
 	  debug_printf ("h %p, horig %p, flags %p", h, horig, oi.dwFlags);
 	  if (horig && h && h != horig && SetProcessWindowStation (horig))
 	    CloseWindowStation (h);


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019