popup consoles on Windows 7
Corinna Vinschen
corinna-cygwin@cygwin.com
Fri Jun 26 16:29:00 GMT 2009
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
More information about the Cygwin
mailing list