Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit 32301d6

Browse files
✨ Add runAsAdmin
1 parent 3851d8e commit 32301d6

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

app.ahk

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ config := readConfig()
1616
hiddenWindowMap := Map()
1717
hiddenWindowMenu := 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()
1938
class 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(

scripts/configuration.ahk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CONFIG_DEFAULT := UMap(
2727
"misc", UMap(
2828
"autoStart", false,
2929
"minimizeToTray", true,
30+
"runAsAdmin", false,
3031
"hideTray", false,
3132
"reuseExistingWindow", true,
3233
"singleActiveWindow", false,

0 commit comments

Comments
 (0)