Re: Bring window from elevated process to front in Vista
- From: "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 26 Feb 2008 10:04:12 -0800
"Steph" <steph@xxxxxxxxxxxxxxxxx> wrote in message
news:9B64EE13-5148-4E62-8193-624F4D71D5E5@xxxxxxxxxxxxxxxx
Hi,
I'm writing a task switching application and am having difficulty in
giving
a window belonging to an elevated process the focus.
The code I usually use:
WINDOWPLACEMENT lpwndpl;
lpwndpl.length = sizeof(WINDOWPLACEMENT);
::GetWindowPlacement( hwndAppWindow, &lpwndpl);
::BringWindowToTop (hwndAppWindow);
if (lpwndpl.showCmd == SW_SHOWMINIMIZED)
{
::ShowWindow (hwndAppWindow, SW_RESTORE);
}
::SetFocus (hwndAppWindow);
is returning "Access is denied" for BringWindowToTop, ShowWindow and
SetFocus. (hwndAppWindow is returned by FindWindow)
I've tried calling AllowSetForegroundWindow(ASFW_ANY) in both the task
switch app and the elevated app without success, and the dialogs of both
programs have the Set Foreground property set to True, but still it fails.
I
also tried using SetWindowPos which also returns an "Access is denied"
error.
Can someone please tell me if it's possible to do this, and give me some
pointers?
Note that the above code works for windows of non-elevated apps.
I'm using VS2008 and Windows Vista.
If Windows Vista has UAC (User Access Control) enabled (it is by default),
then Windows prevents a non-elevated app from manipulating the Windows of an
elevated app. In order to do so, your app needs to be elevated itself. For
your app to elevate, the user must accept this (the screen darkens and a
dialog asking for the Admin password or, if an Admin is logged in, a simple
OK button click). This is a royal pain. The only way around it that I have
heard is if you put your app into the Windows Scheduler, which can start the
app as elevated without further approval.
-- David
.
- Follow-Ups:
- Re: Bring window from elevated process to front in Vista
- From: Ajay Kalra
- Re: Bring window from elevated process to front in Vista
- Prev by Date: Re: CoInitialize returns FALSE?
- Next by Date: Re: CoInitialize returns FALSE?
- Previous by thread: Re: Bring window from elevated process to front in Vista
- Next by thread: Re: Bring window from elevated process to front in Vista
- Index(es):
Relevant Pages
|