Skip to content

Commit

Permalink
some restructioning and update to v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lightproof committed Jun 6, 2023
1 parent 59cbd4f commit 0995c8f
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 27 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*/
# folders
/*
!/assets

# files
*.exe

110 changes: 91 additions & 19 deletions UAC-Focus.ahk
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
;
; UAC-Focus
;
; AHK script that focuses UAC window for quick control with keyboard shortcuts.
; An AutoHotKey script that focuses UAC window for quick control with keyboard shortcuts.
;
; https://github.com/lightproof/UAC-Focus
;
;
; Instructions:
; How to use:
; Run the script with the highest privileges as "NT AUTHORITY\SYSTEM". See GitHub page for more details.
;
;
; Startup parameters:
; -notify - display notification when UAC window gets focused by the script
; -notifyall - also display notification when UAC window appears already focused
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



; Basics
version = v0.2.0
#SingleInstance Force



; Vars
version = v0.4.0
appname = UAC-Focus by lightproof
repo = https://github.com/lightproof/UAC-Focus
appicon = icon.ico
RunMode = silent



; App icon
appicon = %a_scriptdir%/assets/icon.ico

IfExist, %appicon%
Menu, Tray, Icon, icon.ico

Menu, Tray, Icon, %appicon%

; Menu & settings


; Command line arguments
arg = %1%

if arg = -notify
RunMode = notify

if arg = -notifyall
RunMode = notifyall



; Tray menu
Menu, Tray, Tip, UAC-Focus %version%
Menu, Tray, Click, 2
Menu, Tray, NoStandard


; Menu body
Menu, Tray, Add, &About, about, :FileMenu
Menu, Tray, Default, &About
Menu, Tray, Add
Menu, Tray, Add, &GitHub page, github
Menu, Tray, Add, &Help, help
Menu, Tray, Add, &Open file location, OpenLocation
Menu, Tray, Add
Menu, Tray, Add, E&xit, quit



; Main loop
; Main detect and focus loop
Loop
{

Expand All @@ -48,13 +74,14 @@
{

WinActivate
; TrayTip, UAC-Focus, Window focused, 3, 1 ;uncomment for message to appear every time the UAC window is focused


if RunMode = notify
TrayTip, UAC-Focus, Window focused, 3, 1
}
else
{

; TrayTip, UAC-Focus, Already in focus, 3, 1 ;uncomment for message to appear every time the UAC window appears already focused
if RunMode = notifyall
TrayTip, UAC-Focus, Already in focus, 3, 1

}

Expand All @@ -64,9 +91,49 @@



; Menu targets
; Subroutines
help:
MsgBox, 64, %appname%,
(LTrim
Startup parameters:

-notify - display notification when UAC window gets focused by the script

-notifyall - also display notification when UAC window is shown already focused
)
return


about:
MsgBox, 64, UAC-Focus, UAC-Focus by Lightproof, %version%`n`n%repo%
OnMessage(0x53, "WM_HELP")
Gui +OwnDialogs

SetTimer, ButtonRename, 10

MsgBox, 0x4040, About,
(LTrim
%appname% %version%

An AutoHotKey script that automatically focuses UAC window for quick control with keyboard shortcuts.

%repo%
)


WM_HELP() {
Gosub, github
WinClose, %appname% ahk_class #32770
}
return


ButtonRename:
IfWinNotExist, About aHK_class #32770
return

SetTimer, ButtonRename, Off
WinActivate
ControlSetText, Button2, &GitHub
return


Expand All @@ -75,5 +142,10 @@
return


OpenLocation:
run, explorer.exe %a_scriptdir%
return


quit:
ExitApp
ExitApp
Binary file added assets/icon.ico
Binary file not shown.
Binary file added assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icon.ico
Binary file not shown.
19 changes: 12 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
## UAC-Focus
## ![icon](assets/icon.png?raw=true) UAC-Focus

### ABOUT

##### ABOUT
This is a simple AutoHotKey script that makes it easier to control UAC Prompts with the use of keyboard shortcuts (`Alt`+`Y` / `Alt`+`N`)[^1]. It have been tested to work on Windows 10 21H2, but should probably also work on Windows 11, 8/8.1 and maybe even 7 or Vista.

##### Rationale:
#### Rationale:

By default Windows UAC is set up to run on a secure (dimmed) desktop. Consequently, the UAC Prompt window is always in focus when it appears, and is easy to control using the keyboard. If, however, UAC is set up to run on a regular desktop, the UAC Prompt window doesn't always come up in focus, making it inconvenient to control with the keyboard, forcing the user to explicitly switch to UAC window first using either mouse or `Alt`+`Tab`.

##### The solution:
#### Solution:

This AutoHotKey script waits for the UAC Prompt window to appear and then brings it in focus, making keyboard shortcuts usage more convenient.

##### HOW TO USE
## HOW TO USE

The UAC Prompt host process (consent.exe) runs under SYSTEM account and cannot be easily accessed due to security reasons. Because of this the script must be run with the highest privileges (as `NT Authority\System`).

There are several ways to do this:
Expand All @@ -20,9 +24,10 @@ There are several ways to do this:

3. using Windows **Task Scheduler** task with `Run with highest privileges` setting enabled.[^4]


---
##### DISCLAIMER

### DISCLAIMER

Running a process as a System user is a potential security risk and is usually discouraged. Although this script is probably unlikely to compromise system security, it, nevertheless, comes with ABSOLUTELY NO WARRANTY and you are using it AT YOUR OWN RISK. You have been warned.

[^1]: this is a default for a non-localized (i.e. english) Windows UI. If the UI is in another language, the letter corresponding to each option can be found out by pressing `Alt` twice while UAC window is open.
Expand Down

0 comments on commit 0995c8f

Please sign in to comment.