Skip to content

Commit 0995c8f

Browse files
committed
some restructioning and update to v0.4.0
1 parent 59cbd4f commit 0995c8f

File tree

6 files changed

+108
-27
lines changed

6 files changed

+108
-27
lines changed

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
/*/
1+
# folders
2+
/*
3+
!/assets
4+
5+
# files
26
*.exe
37

UAC-Focus.ahk

+91-19
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,70 @@
11
;
22
; UAC-Focus
33
;
4-
; AHK script that focuses UAC window for quick control with keyboard shortcuts.
4+
; An AutoHotKey script that focuses UAC window for quick control with keyboard shortcuts.
55
;
66
; https://github.com/lightproof/UAC-Focus
77
;
88
;
9-
; Instructions:
9+
; How to use:
1010
; Run the script with the highest privileges as "NT AUTHORITY\SYSTEM". See GitHub page for more details.
1111
;
12+
;
13+
; Startup parameters:
14+
; -notify - display notification when UAC window gets focused by the script
15+
; -notifyall - also display notification when UAC window appears already focused
16+
;
1217
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1318

1419

1520

16-
; Basics
17-
version = v0.2.0
21+
#SingleInstance Force
22+
23+
24+
25+
; Vars
26+
version = v0.4.0
27+
appname = UAC-Focus by lightproof
1828
repo = https://github.com/lightproof/UAC-Focus
19-
appicon = icon.ico
29+
RunMode = silent
30+
31+
32+
33+
; App icon
34+
appicon = %a_scriptdir%/assets/icon.ico
2035

2136
IfExist, %appicon%
22-
Menu, Tray, Icon, icon.ico
23-
37+
Menu, Tray, Icon, %appicon%
2438

25-
; Menu & settings
39+
40+
41+
; Command line arguments
42+
arg = %1%
43+
44+
if arg = -notify
45+
RunMode = notify
46+
47+
if arg = -notifyall
48+
RunMode = notifyall
49+
50+
51+
52+
; Tray menu
2653
Menu, Tray, Tip, UAC-Focus %version%
2754
Menu, Tray, Click, 2
2855
Menu, Tray, NoStandard
2956

30-
31-
; Menu body
3257
Menu, Tray, Add, &About, about, :FileMenu
3358
Menu, Tray, Default, &About
3459
Menu, Tray, Add
35-
Menu, Tray, Add, &GitHub page, github
60+
Menu, Tray, Add, &Help, help
61+
Menu, Tray, Add, &Open file location, OpenLocation
3662
Menu, Tray, Add
3763
Menu, Tray, Add, E&xit, quit
3864

3965

4066

41-
; Main loop
67+
; Main detect and focus loop
4268
Loop
4369
{
4470

@@ -48,13 +74,14 @@
4874
{
4975

5076
WinActivate
51-
; TrayTip, UAC-Focus, Window focused, 3, 1 ;uncomment for message to appear every time the UAC window is focused
52-
77+
78+
if RunMode = notify
79+
TrayTip, UAC-Focus, Window focused, 3, 1
5380
}
5481
else
5582
{
56-
57-
; TrayTip, UAC-Focus, Already in focus, 3, 1 ;uncomment for message to appear every time the UAC window appears already focused
83+
if RunMode = notifyall
84+
TrayTip, UAC-Focus, Already in focus, 3, 1
5885

5986
}
6087

@@ -64,9 +91,49 @@
6491

6592

6693

67-
; Menu targets
94+
; Subroutines
95+
help:
96+
MsgBox, 64, %appname%,
97+
(LTrim
98+
Startup parameters:
99+
100+
-notify - display notification when UAC window gets focused by the script
101+
102+
-notifyall - also display notification when UAC window is shown already focused
103+
)
104+
return
105+
106+
68107
about:
69-
MsgBox, 64, UAC-Focus, UAC-Focus by Lightproof, %version%`n`n%repo%
108+
OnMessage(0x53, "WM_HELP")
109+
Gui +OwnDialogs
110+
111+
SetTimer, ButtonRename, 10
112+
113+
MsgBox, 0x4040, About,
114+
(LTrim
115+
%appname% %version%
116+
117+
An AutoHotKey script that automatically focuses UAC window for quick control with keyboard shortcuts.
118+
119+
%repo%
120+
)
121+
122+
123+
WM_HELP() {
124+
Gosub, github
125+
WinClose, %appname% ahk_class #32770
126+
}
127+
return
128+
129+
130+
ButtonRename:
131+
IfWinNotExist, About aHK_class #32770
132+
return
133+
134+
SetTimer, ButtonRename, Off
135+
WinActivate
136+
ControlSetText, Button2, &GitHub
70137
return
71138

72139

@@ -75,5 +142,10 @@
75142
return
76143

77144

145+
OpenLocation:
146+
run, explorer.exe %a_scriptdir%
147+
return
148+
149+
78150
quit:
79-
ExitApp
151+
ExitApp

assets/icon.ico

4.19 KB
Binary file not shown.

assets/icon.png

4.76 KB
Loading

icon.ico

-21.3 KB
Binary file not shown.

readme.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
## UAC-Focus
1+
## ![icon](assets/icon.png?raw=true) UAC-Focus
2+
3+
### ABOUT
24

3-
##### ABOUT
45
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.
56

6-
##### Rationale:
7+
#### Rationale:
8+
79
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`.
810

9-
##### The solution:
11+
#### Solution:
12+
1013
This AutoHotKey script waits for the UAC Prompt window to appear and then brings it in focus, making keyboard shortcuts usage more convenient.
1114

12-
##### HOW TO USE
15+
## HOW TO USE
16+
1317
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`).
1418

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

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

23-
2427
---
25-
##### DISCLAIMER
28+
29+
### DISCLAIMER
30+
2631
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.
2732

2833
[^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.

0 commit comments

Comments
 (0)