@@ -16,6 +16,25 @@ config := readConfig()
1616hiddenWindowMap := Map()
1717hiddenWindowMenu := Menu ()
1818
19+ full_command_line := DllCall (" GetCommandLine" , " str" )
20+
21+ restartAsAdmin () {
22+ if (config[" misc" ][" runAsAdmin" ]) {
23+ if not (A_IsAdmin or RegExMatch (full_command_line, " /restart(?!\S)" ))
24+ {
25+ try
26+ {
27+ if A_IsCompiled
28+ Run '* RunAs " ' A_ScriptFullPath '" ' JoinStrs(A_Args, " " ) ' / restart'
29+ else
30+ Run '* RunAs " ' A_AhkPath '" / restart " ' A_ScriptFullPath '" ' JoinStrs(A_Args, " " )
31+ }
32+ ExitApp ()
33+ }
34+ }
35+ }
36+
37+ restartAsAdmin()
1938class Configurator {
2039 __New () {
2140 global config
@@ -37,6 +56,7 @@ class Configurator {
3756 }
3857 this.subGuis := []
3958 if (! this.config[" misc" ][" minimizeToTray" ] || ! this.isMainRunning) {
59+ A_TrayMenu.Delete ()
4060 ExitApp ()
4161 }
4262 })
@@ -83,6 +103,7 @@ class Configurator {
83103 this._stopMainScript()
84104 ; Sleep(100)
85105 writeConfig(this.config)
106+ restartAsAdmin()
86107 this._startMainScript()
87108 }
88109 updateTray()
@@ -462,6 +483,7 @@ class Configurator {
462483 miscConfig := this.config[" misc" ]
463484 this.gui .AddText(" section xs ys c676767" , " 通用" )
464485 this._addComponent(this.COMPONENT_CLASS.CHECKBOX, " 开机自启动" , miscConfig, " autoStart" )
486+ this._addComponent(this.COMPONENT_CLASS.CHECKBOX, " 以管理员身份运行" , miscConfig, " runAsAdmin" )
465487 this._addComponent(this.COMPONENT_CLASS.CHECKBOX, " 后台运行" , miscConfig, " minimizeToTray" )
466488 this._addComponent(this.COMPONENT_CLASS.CHECKBOX, " 后台运行时隐藏托盘图标" , miscConfig, " hideTray" )
467489 this.gui .AddLink(S({ x: " +0" , y: " s+1" }), '(<a href=" /" >注意</ a>)').OnEvent(
0 commit comments