Sign in to follow this  
Followers 0

UAC Prompt Help

10 posts in this topic

Posted

Okay, basically I've been trying to make a hotfix for when this happens:

Posted Image

I've looked through the documentation, however I can't figure out how to activate it and title matching doesn't seem to want to work. Anyone know how to activate the prompt?

Share this post


Link to post
Share on other sites



Posted

Why not just use #RequireAdmin at the beginning of your script?

Share this post


Link to post
Share on other sites

Posted (edited)

Why not just use #RequireAdmin at the beginning of your script?

Because it's not my script that is using causing the UAC prompt. It's a different program Secondily, I'm not trying to automate launching a program as admin. I'm trying to activate a window.

Edited by rcmaehl

Share this post


Link to post
Share on other sites

Posted

Not really beautiful, but works as a last resort...

#include <winapi.au3>

While 1
    Sleep(250)
    If ProcessExists("consent.exe") Then
        $aWinList = _WinGetAltTabWinList()
        For $i = 0 To $aWinList[0][0]
            If Not ProcessExists("consent.exe") Then ExitLoop
            Send("{ALTDOWN}")
            Send("{TAB " & $i + 1 & "}")
            Send("{ALTUP}")
        Next
    EndIf
WEnd

; http://www.autoitscript.com/forum/topic/90282-wingetalttabwinlist/
; ===============================================================================================================================
; Func _WinGetAltTabWinList($sTitle="",$sText="",$bGetClassName=False)
;
; Returns list of visible Alt-Tab-able windows.
;
; $sTitle = (optional) Title of window, or window handle to send to initial WinList() call
; $sText = (optional) Visible text in window, same as WinList() call
; $bGetClassName = If True, a 3rd column will be created in the array containing the Window's class name
;
; Returns:
;    Success: An array of Windows in the same style as WinList, with an optional 3rd column (depending on $bGetClassName):
;        [0][0]  = Count of Windows
;        [$i][0] = Window Title
;        [$i][1] = Window Handle
;      And optionally (if $bGetClassName=True):
;        [$i][2] = Window Class Name
;    Failure: A 1-element array same as WinList, with [0][0] = 0, and @error set
;        @error = 0 = WinList returned matches, but nothing matched Alt-Tab-able windows
;        @error = 1 = WinList return no matches
;
; Author: Ascend4nt (based on code by Authenticity)
; ===============================================================================================================================

Func _WinGetAltTabWinList($sTitle = "", $sText = "", $bGetClassName = False)
    Local $aWinList, $i2ndDim = 2, $iCount = 0, $iExStyle

    ; Since passing an empty string or 'Default' keyword for 1st parameter
    ;  causes WinList to return incorrect results, we test first
    If $sTitle <> "" Then
        $aWinList = WinList($sTitle, $sText)
    Else
        $aWinList = WinList()
    EndIf

    ; Does the caller want the Class name also?
    If $bGetClassName Then $i2ndDim += 1

    ; Set initial dimensions to match WinList's, + any extra column(s)
    Dim $aAltTabList[$aWinList[0][0] + 1][$i2ndDim]
    $aAltTabList[0][0] = 0 ; zero count out for possible error returns

    ; Check to see if any Windows matched, given the parameters. If not, return empty list
    If $aWinList[0][0] = 0 Then Return SetError(1, 0, $aAltTabList)

    For $i = 1 To $aWinList[0][0]
        If BitAND(WinGetState($aWinList[$i][1]), 2) Then ; Is it Visible?
            $iExStyle = _WinAPI_GetWindowLong($aWinList[$i][1], -20) ; Get Extended Style bits
            ; Extended Style bits WS_EX_NOACTIVATE (0x08000000) and WS_EX_TOOLWINDOW (0x80) indicate non-Alt-Tab windows,
            ;    but if bit WS_EX_APPWINDOW (0x040000) is set, then it is still Alt-Tab-able
            If BitAND($iExStyle, 0x08000080) = 0 Or BitAND($iExStyle, 0x040000) Then
                $iCount += 1
                $aAltTabList[$iCount][0] = $aWinList[$i][0]
                $aAltTabList[$iCount][1] = $aWinList[$i][1]
                If $bGetClassName Then $aAltTabList[$iCount][2] = _WinAPI_GetClassName($aWinList[$i][1])
            EndIf
        EndIf
    Next

    ; Redimension array to results size
    ReDim $aAltTabList[$iCount + 1][$i2ndDim]
    $aAltTabList[0][0] = $iCount

    Return $aAltTabList
EndFunc   ;==>_WinGetAltTabWinList

Share this post


Link to post
Share on other sites

Posted

Not really beautiful, but works as a last resort...

#include <winapi.au3>

While 1
    Sleep(250)
    If ProcessExists("consent.exe") Then
        $aWinList = _WinGetAltTabWinList()
        For $i = 0 To $aWinList[0][0]
            If Not ProcessExists("consent.exe") Then ExitLoop
            Send("{ALTDOWN}")
            Send("{TAB " & $i + 1 & "}")
            Send("{ALTUP}")
        Next
    EndIf
WEnd

; http://www.autoitscript.com/forum/topic/90282-wingetalttabwinlist/
; ===============================================================================================================================
; Func _WinGetAltTabWinList($sTitle="",$sText="",$bGetClassName=False)
;
; Returns list of visible Alt-Tab-able windows.
;
; $sTitle = (optional) Title of window, or window handle to send to initial WinList() call
; $sText = (optional) Visible text in window, same as WinList() call
; $bGetClassName = If True, a 3rd column will be created in the array containing the Window's class name
;
; Returns:
;   Success: An array of Windows in the same style as WinList, with an optional 3rd column (depending on $bGetClassName):
;       [0][0]  = Count of Windows
;       [$i][0] = Window Title
;       [$i][1] = Window Handle
;     And optionally (if $bGetClassName=True):
;       [$i][2] = Window Class Name
;   Failure: A 1-element array same as WinList, with [0][0] = 0, and @error set
;       @error = 0 = WinList returned matches, but nothing matched Alt-Tab-able windows
;       @error = 1 = WinList return no matches
;
; Author: Ascend4nt (based on code by Authenticity)
; ===============================================================================================================================

Func _WinGetAltTabWinList($sTitle = "", $sText = "", $bGetClassName = False)
    Local $aWinList, $i2ndDim = 2, $iCount = 0, $iExStyle

    ; Since passing an empty string or 'Default' keyword for 1st parameter
    ;  causes WinList to return incorrect results, we test first
    If $sTitle <> "" Then
        $aWinList = WinList($sTitle, $sText)
    Else
        $aWinList = WinList()
    EndIf

    ; Does the caller want the Class name also?
    If $bGetClassName Then $i2ndDim += 1

    ; Set initial dimensions to match WinList's, + any extra column(s)
    Dim $aAltTabList[$aWinList[0][0] + 1][$i2ndDim]
    $aAltTabList[0][0] = 0 ; zero count out for possible error returns

    ; Check to see if any Windows matched, given the parameters. If not, return empty list
    If $aWinList[0][0] = 0 Then Return SetError(1, 0, $aAltTabList)

    For $i = 1 To $aWinList[0][0]
        If BitAND(WinGetState($aWinList[$i][1]), 2) Then ; Is it Visible?
            $iExStyle = _WinAPI_GetWindowLong($aWinList[$i][1], -20) ; Get Extended Style bits
            ; Extended Style bits WS_EX_NOACTIVATE (0x08000000) and WS_EX_TOOLWINDOW (0x80) indicate non-Alt-Tab windows,
            ;   but if bit WS_EX_APPWINDOW (0x040000) is set, then it is still Alt-Tab-able
            If BitAND($iExStyle, 0x08000080) = 0 Or BitAND($iExStyle, 0x040000) Then
                $iCount += 1
                $aAltTabList[$iCount][0] = $aWinList[$i][0]
                $aAltTabList[$iCount][1] = $aWinList[$i][1]
                If $bGetClassName Then $aAltTabList[$iCount][2] = _WinAPI_GetClassName($aWinList[$i][1])
            EndIf
        EndIf
    Next

    ; Redimension array to results size
    ReDim $aAltTabList[$iCount + 1][$i2ndDim]
    $aAltTabList[0][0] = $iCount

    Return $aAltTabList
EndFunc   ;==>_WinGetAltTabWinList

Not pretty, it works, however is there any other ways other than this. I'll use this for now until I find a better way.

Share this post


Link to post
Share on other sites

Posted

Not pretty...

Heard of the term don't look a gift horse in the mouth? If not look it up!

Share this post


Link to post
Share on other sites

Posted

Heard of the term don't look a gift horse in the mouth? If not look it up!

Just did. Interesting.

Share this post


Link to post
Share on other sites

Posted

What about something like this?

#include "_ProcessGetWin.au3" ; http://www.autoitscript.com/forum/topic/115243-processgetwin/
While 1
    Sleep(200)
    $iConsent = ProcessExists("consent.exe")
    If $iConsent Then
        $aWins = _ProcessGetWin($iConsent)
        $hTheWindow = ... ; find the correct window in $aWins
        WinActivate($hTheWindow)
        WinWaitNotActive($hTheWindow)
    EndIf
WEnd

Share this post


Link to post
Share on other sites

Posted (edited)

Hm, the _ProcessGetWin function did not find the UAC window for me. Additionally it seems not possible to activate a found UAC window with a plain WinActivate.

But during my research I've found this nice article on stackoverflow.com :oops:...

#include <winapi.au3>

HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(250)
    $hWnd_UAC = WinGetHandle("[REGEXPCLASS:$$$Secure UAP]")
    If $hWnd_UAC Then _WinAPI_SwitchToThisWindow($hWnd_UAC, True)
WEnd

Func _WinAPI_SwitchToThisWindow($hWnd, $bAltTab = False)
    DllCall("user32.dll", "int", "SwitchToThisWindow", "hwnd", $hWnd, "bool", $bAltTab)
EndFunc   ;==>_WinAPI_SwitchToThisWindow

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by KaFu

Share this post


Link to post
Share on other sites

Posted

I actually made a fix for this myself. Took a few hours to get right, but I basically did a pixel search on the task bar for a small square that would contain the same colors as the center of the UAC icon and then mouse click in the middle of that square on the task bar when consent.exe exists, however it seems your fix works better and faster.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.