Re: Bring window from elevated process to front in Vista

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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


.



Relevant Pages

  • Re: Bring window from elevated process to front in Vista
    ... switch app and the elevated app without success, ... If Windows Vista has UAC enabled, ... 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 ...
    (microsoft.public.vc.mfc)
  • Re: Windows 7, another Windows Vista?
    ... Windows 7 is not. ... But Vista did: remember how apps used to have "menu bars"? ... wants to elevate to admin. ...
    (comp.sys.mac.advocacy)
  • Re: Estending the time until "Not Responding"
    ... You probably would have to elevate regedit to change ... Theres no entry in the registry called HungAppTimeOut. ... See link below which references Windows 2K but seems to be the same in XP ... The "Ultimate Windows Tweaker - Tweak UI For Windows Vista" can also ...
    (microsoft.public.windows.vista.general)
  • Re: For Vista: Programmatically "elevate" my app for a particular task.
    ... I forgot to say that OS running my app is Windows Vista. ... so elevate my app permisions from that moment on. ...
    (microsoft.public.vc.mfc)
  • Re: Windows 7, another Windows Vista?
    ... the shell is visible and usable even in other applications... ... Windows 7 doesn't really differ noticeably from Vista in this area. ... It will still only silently elevate its own COM objects, and only a signed process can elevate them silently. ... No fancy-pants code injection required for that one. ...
    (comp.sys.mac.advocacy)